Repository navigation
Modify FileUtil.toPath to never return null
#9820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+4,914
−111
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
platform/o.n.bootstrap/src/org/netbeans/NbFileTypeDetector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.netbeans; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.spi.FileTypeDetector; | ||
| import org.openide.util.Lookup; | ||
| import org.openide.util.lookup.ServiceProvider; | ||
|
|
||
| /** Delegates to other detectors registered in the NetBeans runtime. | ||
| * <p> | ||
| * {@code Files.probeContentType }loads installed detectors with | ||
| * {@code ServiceLoader.load(FileTypeDetector.class, ClassLoader.getSystemClassLoader())}. | ||
| * In the running IDE registered detectors are however loaded by different classloaders. | ||
| * To mitigate that this class (registered on NetBeans application classapath) | ||
| * obtains all registered detectors (including | ||
| * {@code org.netbeans.modules.openide.filesystems.declmime.NioFileTypeDetector}) | ||
| * and delegates to them explicitly. | ||
| */ | ||
| @ServiceProvider(service = FileTypeDetector.class) | ||
| public final class NbFileTypeDetector extends FileTypeDetector { | ||
| private final Lookup.Result<FileTypeDetector> all; | ||
|
|
||
| public NbFileTypeDetector() { | ||
| all = Lookup.getDefault().lookupResult(FileTypeDetector.class); | ||
| } | ||
|
|
||
| @Override | ||
| public String probeContentType(Path path) throws IOException { | ||
| for (FileTypeDetector detector : all.allInstances()) { | ||
| if (detector == this) { | ||
| continue; | ||
| } | ||
|
|
||
| String mime = detector.probeContentType(path); | ||
| if (mime != null) { | ||
| return mime; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...m/o.n.core/test/qa-functional/src/org/netbeans/core/validation/ValidateMimeTypesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.netbeans.core.validation; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import junit.framework.Test; | ||
| import junit.framework.TestSuite; | ||
| import org.netbeans.junit.NbModuleSuite; | ||
| import org.netbeans.junit.NbTestCase; | ||
| import org.openide.filesystems.FileUtil; | ||
|
|
||
| /** Checks that {@link Files#pr} and {@link FileObject#get} are consistent | ||
| * when running in the NetBeans IDE and platform. Goes thru all | ||
| * the templates and verifies their mime types. | ||
| */ | ||
| public final class ValidateMimeTypesTest extends NbTestCase { | ||
| public ValidateMimeTypesTest(String name) { | ||
| super(name); | ||
| } | ||
|
|
||
|
|
||
| public static Test suite() { | ||
| TestSuite suite = new TestSuite(); | ||
| suite.addTest(NbModuleSuite.createConfiguration(ValidateMimeTypesTest.class) | ||
| .clusters("(?!ergonomics).*") | ||
| .enableClasspathModules(false) | ||
| .enableModules(".*") | ||
| .gui(false).suite() | ||
| ); | ||
| return suite; | ||
| } | ||
|
|
||
| public void testCheckTemplatesMimeTypes() throws IOException { | ||
| var errors = new StringBuilder(); | ||
|
|
||
| var root = FileUtil.getConfigFile("Templates"); | ||
| assertNotNull("Templates directory found", root); | ||
| var en = root.getChildren(true); | ||
| while (en.hasMoreElements()) { | ||
| var file = en.nextElement(); | ||
| if (file.isFolder()) { | ||
| continue; | ||
| } | ||
| var path = FileUtil.toPath(file); | ||
| assertNotNull("Path found for " + file, path); | ||
| var nbMime = file.getMIMEType(); | ||
| var jdkMime = Files.probeContentType(path); | ||
|
|
||
| if (nbMime.equals(jdkMime)) { | ||
| continue; | ||
| } | ||
|
|
||
| errors.append("\n") | ||
| .append(file) | ||
| .append(" mime types differ among NetBeans and JDK: ") | ||
| .append(nbMime) | ||
| .append(" != ") | ||
| .append(jdkMime); | ||
| } | ||
| if (!errors.isEmpty()) { | ||
| errors.insert(0, "Found differences in MIME types:"); | ||
| fail(errors.toString()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ilesystems/src/org/netbeans/modules/openide/filesystems/declmime/NioFileTypeDetector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.netbeans.modules.openide.filesystems.declmime; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.nio.file.spi.FileTypeDetector; | ||
|
|
||
| import org.openide.filesystems.FileObject; | ||
| import org.openide.filesystems.FileUtil; | ||
| import org.openide.util.lookup.ServiceProvider; | ||
|
|
||
| @ServiceProvider(service = FileTypeDetector.class, position = 100) | ||
| public final class NioFileTypeDetector extends FileTypeDetector { | ||
| @Override | ||
| public String probeContentType(Path path) { | ||
| FileObject fileObject = FileUtil.toFileObject(path); | ||
| return fileObject == null ? null : fileObject.getMIMEType(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.