Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.netbeans.junit.NbTestSuite;
import org.openide.filesystems.AttributesTestHidden;
import org.openide.filesystems.FileObjectTestHid;
import org.openide.filesystems.PathTestHid;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.FileSystemFactoryHid;
import org.openide.filesystems.FileSystemTestHid;
Expand All @@ -49,6 +50,7 @@ public static Test suite() {
NbTestSuite suite = new NbTestSuite();
suite.addTestSuite(FileSystemTestHid.class);
suite.addTestSuite(FileObjectTestHid.class);
suite.addTestSuite(PathTestHid.class);
suite.addTestSuite(AttributesTestHidden.class);
suite.addTestSuite(XMLFileSystemTestHid.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.netbeans.junit.NbTestSuite;
import org.openide.filesystems.AttributesTestHidden;
import org.openide.filesystems.FileObjectTestHid;
import org.openide.filesystems.PathTestHid;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.FileSystemFactoryHid;
import org.openide.filesystems.FileSystemTestHid;
Expand All @@ -47,6 +48,7 @@ public static Test suite() {
NbTestSuite suite = new NbTestSuite();
suite.addTestSuite(FileSystemTestHid.class);
suite.addTestSuite(FileObjectTestHid.class);
suite.addTestSuite(PathTestHid.class);
suite.addTestSuite(AttributesTestHidden.class);
suite.addTestSuite(XMLFileSystemTestHid.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static NbTestSuite suite(boolean created) {
NbTestSuite suite = new NbTestSuite();
suite.addTestSuite(FileSystemTestHid.class);
suite.addTestSuite(FileObjectTestHid.class);
suite.addTestSuite(PathTestHid.class);
suite.addTestSuite(URLMapperTestHidden.class);
suite.addTestSuite(FileUtilTestHidden.class);
suite.addTestSuite(FileUtilJavaIOFileHidden.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ public boolean accept(File pathname) {
return accepted;
}
});
return childs.length == 0;
return childs.length == 0 && file.delete();
}
return file.delete();
}
Expand Down
59 changes: 59 additions & 0 deletions platform/o.n.bootstrap/src/org/netbeans/NbFileTypeDetector.java
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;
}
}
1 change: 1 addition & 0 deletions platform/o.n.core/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ test.excludes=\

test.config.commit.includes=\
**/ValidateNbinst*Test.class,\
**/ValidateMimeTypesTest.class,\
**/ValidateClassFilesTest.class,\
**/ValidateModulesTest.class
# Test was disable as it was found to be flaky:
Expand Down
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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,26 @@

package org.netbeans.core.validation;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URL;
import java.net.URLConnection;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.jar.Manifest;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.Action;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.netbeans.core.startup.layers.LayerCacheManager;
import org.netbeans.junit.NbModuleSuite;
import org.netbeans.junit.NbTestCase;
import org.netbeans.junit.Log;
import org.netbeans.junit.RandomlyFails;
import org.openide.cookies.InstanceCookie;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileSystem;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.MultiFileSystem;
import org.openide.filesystems.XMLFileSystem;
import org.openide.loaders.DataFolder;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataShadow;
import org.openide.modules.Dependency;
import org.openide.util.Enumerations;
import org.openide.util.Lookup;
import org.openide.util.Mutex;
import org.openide.util.NbCollections;
Expand Down
32 changes: 31 additions & 1 deletion platform/openide.filesystems/apichanges.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,42 @@
under the License.

-->
<!DOCTYPE apichanges PUBLIC "-//NetBeans//DTD API changes list 1.0//EN" "../../nbbuild/javadoctools/apichanges.dtd">
<!DOCTYPE apichanges PUBLIC "-//NetBeans//DTD API changes list 1.1//EN" "../../nbbuild/javadoctools/apichanges-1.1.dtd">
<apichanges>
<apidefs>
<apidef name="filesystems">Filesystems API</apidef>
</apidefs>
<changes>
<change id="fileobject.outputstream.contract">
<api name="filesystems"/>
<summary>FileObject output streams truncate on open and reject writes after close</summary>
<version major="9" minor="50"/>
<date day="1" month="12" year="2026"/>
<author login="jtulach"/>
<compatibility modification="yes" source="compatible" binary="compatible" semantic="incompatible"/>
<description>
Both <a href="@TOP@/org/openide/filesystems/FileObject.html#getOutputStream()">FileObject.getOutputStream()</a>
and <a href="@TOP@/org/openide/filesystems/FileObject.html#getOutputStream(org.openide.filesystems.FileLock)">getOutputStream(FileLock)</a>
truncate the file when the stream is opened, and writing to the stream after
it is closed throws <code>IOException</code>. Implementations of
<code>FileObject</code> must satisfy these requirements.
</description>
<class name="FileObject" package="org.openide.filesystems"/>
</change>
<change id="path4all.file.objects">
<api name="filesystems"/>
<summary>FileUtil.toPath works for every file object</summary>
<version major="9" minor="50"/>
<date day="1" month="12" year="2026"/>
<author login="jtulach"/>
<compatibility addition="yes" semantic="compatible"/>
<description>
<a href="@TOP@/org/openide/filesystems/FileUtil.html#toPath(org.openide.filesystems.FileObject)">FileUtil.toPath</a>
now returns a non-<code>null</code> <code>Path</code> instance
for all file objects, even for virtual ones.
</description>
<class name="FileUtil" package="org.openide.filesystems"/>
</change>
<change id="fileutil.copyposixperms">
<api name="filesystems"/>
<summary>FileObject copy preserves source posix permissions.</summary>
Expand Down
15 changes: 12 additions & 3 deletions platform/openide.filesystems/arch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
-->
<!DOCTYPE api-answers PUBLIC "-//NetBeans//DTD Arch Answers//EN" "../../nbbuild/antsrc/org/netbeans/nbbuild/Arch.dtd" [
<!ENTITY api-questions SYSTEM "../../nbbuild/antsrc/org/netbeans/nbbuild/Arch-api-questions.xml">
<!ATTLIST a target CDATA #IMPLIED>
]>

<api-answers
Expand Down Expand Up @@ -348,7 +349,15 @@ No.
which provide rollback features. Please see MultiFileSystem class javadoc
for more information.
</p>
</api>
</api>
<api name="java.io.File" group="property" type="export" category="stable"
url="@TOP@/org/openide/filesystems/FileUtil.html#toFile(org.openide.filesystems.FileObject)"
>
<a href="@TOP@/org/openide/filesystems/FileUtil.html#toFile(org.openide.filesystems.FileObject)">toFile</a>
reads the <code>java.io.File</code> attribute from the <code>FileObject</code> to
check for a corresponding <code>java.io.File</code>. If the attribute is
<code>null</code>, it may attempt to find a file using URL mapping.
</api>
</answer>


Expand Down Expand Up @@ -857,14 +866,14 @@ No.
-->
<answer id="arch-usecases">
<p>
<a onclick="target='_blank'" href="https://leanpub.com/nbp4beginners">
<a target="_blank" href="https://leanpub.com/nbp4beginners">
<img src="http://wiki.apidesign.org/images/0/03/NetBeansPlatformForBeginners.jpg"
style="float: right"
width="60" height="70" alt="Cover of NetBeans Platform for Beginners book"/>
</a>
For general overview of the filesystem concepts, related topics,
together with code samples, see chapter 3,
of <a onclick="target='_blank'" href="https://leanpub.com/nbp4beginners">NetBeans Platform for Beginners</a>
of <a target="_blank" href="https://leanpub.com/nbp4beginners">NetBeans Platform for Beginners</a>
by Jason Wexbridge and Walter Nyland.
Many of the usecases are described at the
<a href="@TOP@/org/openide/filesystems/doc-files/api.html">overall documentation</a>,
Expand Down
2 changes: 1 addition & 1 deletion platform/openide.filesystems/manifest.mf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Manifest-Version: 1.0
OpenIDE-Module: org.openide.filesystems
OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties
OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml
OpenIDE-Module-Specification-Version: 9.48
OpenIDE-Module-Specification-Version: 9.50


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)
Comment thread
jtulach marked this conversation as resolved.
Resolved
public final class NioFileTypeDetector extends FileTypeDetector {
@Override
public String probeContentType(Path path) {
FileObject fileObject = FileUtil.toFileObject(path);
return fileObject == null ? null : fileObject.getMIMEType();
}
}
Loading
Loading