Skip to content
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

[GITHUB-6970] MultiSourceRootProvider: reduce logging verbosity #6975

Merged
merged 2 commits into from
Jan 22, 2024
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 @@ -82,10 +82,18 @@ public static boolean isSingleSourceFile(FileObject fObj) {
}

public static boolean isSupportedFile(FileObject file) {
if (file == null) {
return false;
}
try {
return !MultiSourceRootProvider.DISABLE_MULTI_SOURCE_ROOT &&
FileOwnerQuery.getOwner(file) == null &&
!file.getFileSystem().isReadOnly();
FileObject dir = file.getParent();
File dirFile = dir != null ? FileUtil.toFile(dir) : null;
return !MultiSourceRootProvider.DISABLE_MULTI_SOURCE_ROOT
&& FileOwnerQuery.getOwner(file) == null
&& !file.getFileSystem().isReadOnly()
&& !(dirFile != null
&& dirFile.getName().startsWith("vcs-")
&& dirFile.getAbsolutePath().startsWith(System.getProperty("java.io.tmpdir")));
Comment on lines +85 to +96
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: this growing chain of seemingly unrelated conditions might look better when torn apart into multiple checks:

if (file == null || MultiSourceRootProvider.DISABLE_MULTI_SOURCE_ROOT) {
    return false;
}

try {
    if (fileConditionsFail)
        return false,
    }
    File dirFile = ...
    if (parentConditionsFail) {
        return false;
    }
    return true;

} catch (FileStateInvalidException ex) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.IOException;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -35,6 +33,8 @@
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.netbeans.api.java.classpath.ClassPath;
Expand All @@ -50,15 +50,16 @@
import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation;
import org.netbeans.spi.java.classpath.ClassPathFactory;
import org.netbeans.spi.java.classpath.ClassPathImplementation;

import static org.netbeans.spi.java.classpath.ClassPathImplementation.PROP_RESOURCES;

import org.netbeans.spi.java.classpath.ClassPathProvider;
import org.netbeans.spi.java.classpath.FilteringPathResourceImplementation;
import org.netbeans.spi.java.classpath.PathResourceImplementation;
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.URLMapper;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle.Messages;
import org.openide.util.lookup.ServiceProvider;
import org.openide.util.lookup.ServiceProviders;
Expand All @@ -69,6 +70,8 @@
})
public class MultiSourceRootProvider implements ClassPathProvider {

private static final Logger LOG = Logger.getLogger(MultiSourceRootProvider.class.getName());

public static boolean DISABLE_MULTI_SOURCE_ROOT = false;

//TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
Expand Down Expand Up @@ -130,7 +133,7 @@ private ClassPath getSourcePath(FileObject file) {
return srcCP;
});
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
LOG.log(Level.FINE, "Failed to read sourcefile " + file, ex);
}
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
*/
package org.netbeans.modules.java.file.launcher;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.junit.Test;

import static org.junit.Assert.*;

import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.Lookup;
Expand Down Expand Up @@ -51,4 +55,31 @@ public void testCanFindSiblingClass() throws IOException {

assertTrue("Sibling found", SingleSourceFileUtil.hasClassSibling(java));
}

@Test
public void testIsSupportedFile() throws IOException {
File vcsDemoDir = null;
File supportedFile = null;
File unsupportedFile = null;
try {
vcsDemoDir = Files.createTempDirectory("vcs-dummy").toFile();
supportedFile = Files.createTempFile("dummy", ".java").toFile();
unsupportedFile = new File(vcsDemoDir, "dummy.java");
FileUtil.createData(unsupportedFile);

assertTrue(SingleSourceFileUtil.isSupportedFile(FileUtil.createData(supportedFile)));
assertFalse(SingleSourceFileUtil.isSupportedFile(FileUtil.createData(unsupportedFile)));

} finally {
if(supportedFile != null && supportedFile.exists()) {
supportedFile.delete();
}
if(unsupportedFile != null && unsupportedFile.exists()) {
unsupportedFile.delete();
}
if(vcsDemoDir != null && vcsDemoDir.exists()) {
vcsDemoDir.delete();
}
}
}
}
Loading