welovecoding / editorconfig-netbeans

A NetBeans IDE plugin supporting the EditorConfig standard. β›Ί
https://editorconfig.org/
MIT License
127 stars 22 forks source link

Netbeans 8.2 #103

Closed sanishmfod closed 6 years ago

sanishmfod commented 7 years ago

When installing this plugin (v0.10.1) I get the following exception when attempting to open any projects :

v0.10.0 Works as expected

Product Version: NetBeans IDE 8.2 (Build 201609300101) Java: 1.8.0_101; Java HotSpot(TM) 64-Bit Server VM 25.101-b13 Runtime: Java(TM) SE Runtime Environment 1.8.0_101-b13 System: Linux version 4.4.0-47-generic running on amd64; UTF-8; en_GB (nb) Plugin Version : v0.10.1

java.lang.ClassNotFoundException: org.netbeans.spi.project.ui.ProjectOpenedHook
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:222)
Caused: java.lang.ClassNotFoundException: org.netbeans.spi.project.ui.ProjectOpenedHook starting from ModuleCL@5260eb1e[com.welovecoding.netbeans.plugin.editorconfig] with possible defining loaders [ModuleCL@6dc4425e[org.netbeans.modules.projectuiapi], ModuleCL@702dbb46[org.netbeans.modules.projectuiapi.base]] and declared parents [ModuleCL@61e7df45[org.netbeans.modules.parsing.indexing], ModuleCL@6c644b11[org.netbeans.modules.queries], org.netbeans.MainImpl$BootClassLoader@7daf6ecc, ModuleCL@798b2cba[org.netbeans.modules.csl.api], ModuleCL@3d835f75[org.openide.filesystems.nb], ModuleCL@2007f2f7[org.netbeans.modules.projectapi], ModuleCL@124e8334[org.netbeans.modules.editor.mimelookup], ModuleCL@5d036e38[org.netbeans.core.multiview], ModuleCL@3c594181[org.openide.loaders], ModuleCL@5f4b1991[org.netbeans.modules.csl.types], ...17 more]
    at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:224)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Caused: java.lang.NoClassDefFoundError: org/netbeans/spi/project/ui/ProjectOpenedHook
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at org.netbeans.JarClassLoader.doLoadClass(JarClassLoader.java:311)
    at org.netbeans.ProxyClassLoader.selfLoadClass(ProxyClassLoader.java:259)
Caused: java.lang.NoClassDefFoundError: org/netbeans/spi/project/ui/ProjectOpenedHook while loading com.welovecoding.nbeditorconfig.listener.ProjectOpenCloseListener; see http://wiki.netbeans.org/DevFaqTroubleshootClassNotFound
    at org.netbeans.ProxyClassLoader.selfLoadClass(ProxyClassLoader.java:263)
    at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.welovecoding.nbeditorconfig.listener.ProjectHookLookup.createAdditionalLookup(ProjectHookLookup.java:53)
    at org.netbeans.spi.project.support.DelegatingLookupImpl.doDelegate(DelegatingLookupImpl.java:139)
    at org.netbeans.spi.project.support.DelegatingLookupImpl.<init>(DelegatingLookupImpl.java:91)
    at org.netbeans.spi.project.support.LookupProviderSupport.createCompositeLookup(LookupProviderSupport.java:95)
    at org.netbeans.modules.php.project.PhpProject.createLookup(PhpProject.java:781)
    at org.netbeans.modules.php.project.PhpProject.<init>(PhpProject.java:306)
Caused: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.netbeans.modules.project.ant.AntBasedGenericType.createProject(AntBasedGenericType.java:131)
Caused: java.lang.IllegalArgumentException
    at org.netbeans.modules.project.ant.AntBasedGenericType.createProject(AntBasedGenericType.java:140)
    at org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton.loadProject(AntBasedProjectFactorySingleton.java:264)
    at org.netbeans.modules.projectapi.nb.NbProjectManager.createProject(NbProjectManager.java:401)
    at org.netbeans.modules.projectapi.nb.NbProjectManager.access$300(NbProjectManager.java:94)
    at org.netbeans.modules.projectapi.nb.NbProjectManager$2.run(NbProjectManager.java:314)
    at org.netbeans.modules.projectapi.nb.NbProjectManager$2.run(NbProjectManager.java:243)
    at org.netbeans.modules.openide.util.DefaultMutexImplementation.readAccess(DefaultMutexImplementation.java:209)
    at org.openide.util.Mutex.readAccess(Mutex.java:250)
    at org.netbeans.modules.projectapi.nb.NbProjectManager.findProject(NbProjectManager.java:243)
    at org.netbeans.api.project.ProjectManager.findProject(ProjectManager.java:167)
    at org.netbeans.modules.welcome.content.RecentProjectsPanel$OpenProjectAction$1.run(RecentProjectsPanel.java:232)
    at org.netbeans.modules.progress.ui.RunOffEDTImpl$1.run(RunOffEDTImpl.java:169)
    at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1443)
    at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:68)
    at org.openide.util.lookup.Lookups.executeWith(Lookups.java:303)
[catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2058)
sulian commented 7 years ago

I confirm the problem on my NetBeans IDE 8.2 installation (Build 201610071157)

the-melonhead commented 7 years ago

Confirmed on NB 8.2

emabrey commented 7 years ago

I'll take a look at this sometime soon. Can someone assign this to me or give me issue permissions so I can do it myself?

argordmel commented 7 years ago

Confirmed on NB 8.2 MacOS

bennycode commented 7 years ago

Hey @emabrey, thanks for being so proactive! I sent you an invite for collaboration on this project. Once you accept it, I can assign this issue to you.

emabrey commented 7 years ago

πŸ‘ Thanks @bennyn

bennycode commented 7 years ago

You are welcome. Happy to see you here with a "Collaborator" badge. πŸ˜ƒ

emabrey commented 7 years ago

I think I may have fixed this problem locally, but I haven't really figured out what was causing it. I replaced the @LookupProvider.Registration annotation with a @ProjectServiceProvider annotation (including an additional service = LookupProvider.class parameter) within ProjectHookLookup and that seemed to fix the problem. This is the relevant log output from running my modified version locally using Netbeans 8.2:

[INFO] WARNING [org.netbeans.modules.versioning.util.Utils]: associateEncoding() no file object available for C:\Users\emily\AppData\Local\Temp\vcs-1486718692557\vcs-1486718846845\.editorconfig
[INFO] INFO [org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater]: Resolving dependencies took: 7 ms
[INFO] INFO [org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater]: Complete indexing of 0 binary roots took: 1 ms
[INFO] INFO [org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater]: Complete indexing of 0 source roots took: 0 ms (New or modified files: 0, Deleted files: 0) [Adding listeners took: 0 ms]
[INFO] WARNING [org.openide.util.WeakListenerImpl]: Can't remove java.beans.PropertyChangeListener using method org.netbeans.modules.csl.core.GsfDocument.removePropertyChangeListener from org.netbeans.modules.csl.core.GsfDocument@3da3138b, mimeType='text/x-editorconfig', kitClass=null, length=666, version=1, file=com.welovecoding.nbeditorconfig.filetype.EditorConfigDataObject@1b936a79[C:\Users\emily\github_repos\editorconfig-netbeans\target\GUIFormExamples\.editorconfig@e5ffd697:4a28ae79]
[INFO] INFO [org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater]: Resolving dependencies took: 94 ms
[INFO] WARNING [org.netbeans.modules.versioning.util.Utils]: associateEncoding() no file object available for C:\Users\emily\AppData\Local\Temp\vcs-1486718692557\vcs-1486718863007\.editorconfig
[INFO] INFO [org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater]: Complete indexing of 21 binary roots took: 2,681 ms
[INFO] INFO [org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater]: Indexing of: C:\Users\emily\github_repos\editorconfig-netbeans\target\GUIFormExamples\test took: 1 ms (New or modified files: 0, Deleted files: 0) [Adding listeners took: 0 ms]
[INFO] INFO [org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater]: Indexing of: C:\Users\emily\github_repos\editorconfig-netbeans\target\GUIFormExamples\src took: 258 ms (New or modified files: 0, Deleted files: 0) [Adding listeners took: 5 ms]
[INFO] INFO [org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater]: Complete indexing of 2 source roots took: 259 ms (New or modified files: 0, Deleted files: 0) [Adding listeners took: 5 ms]
[INFO] WARNING [org.netbeans.core.TimableEventQueue]: too much time in AWT thread org.netbeans.modules.sampler.InternalSampler@60a77bb0
[INFO] INFO [org.netbeans.core.netigso.Netigso]: bundle org.eclipse.osgi@3.9.1.v20140110-1610 256
[INFO] INFO [org.netbeans.core.netigso.Netigso]: bundle org.eclipse.osgi@3.9.1.v20140110-1610 stopped
[INFO] INFO [org.netbeans.core.netigso.Netigso]: bundle org.eclipse.osgi@3.9.1.v20140110-1610 stopped
[INFO] Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
[INFO] Java HotSpot(TM) 64-Bit Server VM warning: CMSFullGCsBeforeCompaction is deprecated and will likely be removed in a future release.
[INFO] Redirecting output to win32trace remote collector
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

The problem is that I don't quite understand why this is fixing the bug. Can someone chime in an explain if this makes any sense that this would stop the error, or perhaps am I just not able to reproduce the error for some reason?

wadechandler commented 7 years ago

@emabrey I think the base issue is caused by NB platform 81 and 82 moving ProjectOpenedHook to a different dependency, so I think for NB 8.1 and 8.2 and beyond, currently the fix is:

pom.xml:

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <netbeans.api.version>RELEASE81</netbeans.api.version>
    <dependency>
      <groupId>org.netbeans.api</groupId>
      <artifactId>org-netbeans-modules-projectuiapi-base</artifactId>
      <version>${netbeans.api.version}</version>
    </dependency>

So, this is in a different dependency which isn't available in 801 which the plugin depends on.

Too, I think some of the actions are run on background threads, and thus this may be needed in ProjectHookLookup.java:

@LookupProvider.Registration(projectType = {
  "org-netbeans-modules-ant-freeform",
  "org-netbeans-modules-apisupport-project",
  "org-netbeans-modules-apisupport-project-suite",
  "org-netbeans-modules-j2ee-archiveproject",
  "org-netbeans-modules-j2ee-clientproject",
  "org-netbeans-modules-j2ee-earproject",
  "org-netbeans-modules-j2ee-ejbjarproject",
  "org-netbeans-modules-java-j2seproject",
  "org-netbeans-modules-maven",
  "org-netbeans-modules-php-project",
  "org-netbeans-modules-web-clientproject",
  "org-netbeans-modules-web-project"
})
/**
 * Listener for newly opened Projects.
 */
public class ProjectHookLookup implements LookupProvider {

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

  static {
    LOG.setLevel(LISTENER_LOG_LEVEL);
  }

  @Override
  public Lookup createAdditionalLookup(Lookup lookup) {
    final ClassLoader cl = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(ProjectHookLookup.class.getClassLoader());
      final Project project = lookup.lookup(Project.class);
      String projectName = project.getProjectDirectory().getName();

      LOG.log(Level.INFO, "Setup hooks for: {0}", projectName);
      final ProjectOpenCloseListener listener = new ProjectOpenCloseListener(project);
      return Lookups.fixed(listener);
    } finally {
      Thread.currentThread().setContextClassLoader(cl);
    }
  }

}

Notice the setContextClassLoader bit. I can build with mvn clean install -DskipTests at the moment, as the dependencies make tests fail too, so more to figure out, but as a start, I think that is a base. Hope it helps.

wadechandler commented 7 years ago

I can report back though things seem to be working locally with the above changes as I built skipping the tests. There do seem to be issues in that I needed a restart after installing, though after install NB didn't say that, and too, it seems there is some caching of .editorconfig data as I have deleted the file, restarted, and saving doesn't reformat, but using reformat will reformat a file even though .editorconfig file is gone from the project I was using to test. My guess is there are some ways I can contribute to this as I need to use this plugin, and recently discovered it when I ran into this bug in 8.2.

adellanna commented 7 years ago

Tried to install plugin v0.10.1-SNAPSHOT from branch master, then plugin v0.10.1 from tag v0.10.1 Tag v0.10.1 points to v0.1.1 so I installed this version When I tried to install plugins I got the following exception for both versions (v0.10.1-SNAPSHOT and v0.1.1) when attempting to open any projects :

Product Version: NetBeans IDE 8.2 (Build 201609300101) Java: 1.8.0_25; Java HotSpot(TM) 64-Bit Server VM 25.25-b02 Runtime: Java(TM) SE Runtime Environment 1.8.0_25-b17 System: Linux version 3.13.0-48-generic running on amd64; UTF-8; it_IT (nb) Plugin Versions : v0.10.1-SNAPSHOT v0.1.1

java.lang.NoClassDefFoundError: com/welovecoding/nbeditorconfig/listener/ProjectOpenCloseListener at com.welovecoding.nbeditorconfig.listener.ProjectHookLookup.createAdditionalLookup(ProjectHookLookup.java:53) at org.netbeans.spi.project.support.DelegatingLookupImpl.doDelegate(DelegatingLookupImpl.java:139) at org.netbeans.spi.project.support.DelegatingLookupImpl.<init>(DelegatingLookupImpl.java:91) at org.netbeans.spi.project.support.LookupProviderSupport.createCompositeLookup(LookupProviderSupport.java:111) at org.netbeans.modules.maven.NbMavenProjectImpl.<init>(NbMavenProjectImpl.java:266) at org.netbeans.modules.maven.NbMavenProjectFactory.loadProject(NbMavenProjectFactory.java:118) at org.netbeans.modules.projectapi.nb.NbProjectManager.createProject(NbProjectManager.java:401) at org.netbeans.modules.projectapi.nb.NbProjectManager.access$300(NbProjectManager.java:94) at org.netbeans.modules.projectapi.nb.NbProjectManager$2.run(NbProjectManager.java:314) at org.netbeans.modules.projectapi.nb.NbProjectManager$2.run(NbProjectManager.java:243) at org.netbeans.modules.openide.util.DefaultMutexImplementation.readAccess(DefaultMutexImplementation.java:209) at org.openide.util.Mutex.readAccess(Mutex.java:250) at org.netbeans.modules.projectapi.nb.NbProjectManager.findProject(NbProjectManager.java:243) at org.netbeans.api.project.ProjectManager.findProject(ProjectManager.java:167) at org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation.getOwner(SimpleFileOwnerQueryImplementation.java:161) at org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation.getOwner(SimpleFileOwnerQueryImplementation.java:113) at org.netbeans.api.project.FileOwnerQuery.getOwner(FileOwnerQuery.java:150) at org.netbeans.modules.projectapi.ProjectSharabilityQuery2.getSharability(ProjectSharabilityQuery2.java:63) at org.netbeans.api.queries.SharabilityQuery.getSharability(SharabilityQuery.java:177) at org.netbeans.modules.git.utils.GitUtils.isIgnored(GitUtils.java:250) at org.netbeans.modules.git.FileStatusCache.checkForIgnore(FileStatusCache.java:619) at org.netbeans.modules.git.FileStatusCache.refreshStatusesBatch(FileStatusCache.java:593) at org.netbeans.modules.git.FileStatusCache.refreshAllRoots(FileStatusCache.java:274) at org.netbeans.modules.git.FileStatusCache.refreshAllRoots(FileStatusCache.java:193) at org.netbeans.modules.git.FilesystemInterceptor$RefreshTask.run(FilesystemInterceptor.java:692) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1443) at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:68) at org.openide.util.lookup.Lookups.executeWith(Lookups.java:303) [catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2058)

Jenselme commented 7 years ago

Based on @wadechandler comment I was able to fix build and tests on NetBeans 8.2. You can see it here: https://github.com/Jenselme/editorconfig-netbeans/tree/netbeans-82

After some quick testing, it looks like formatting is broken for some JSON files (eg this one) and indentation is not enforced in YAML and SQL files. Don't know if it was before.

bennycode commented 7 years ago

@Jenselme It's great that you push "editorconfig-netbeans" forward! 🌞

@Yserz and I were always hoping to get it into the official NetBeans Plugin Portal one day...

You can download older versions of the "editorconfig-netbeans" plugin from the Releases page to verify if the JSON formatting bug already existed. From my knowledge it was okay.

Jenselme commented 7 years ago

I can open a pull request for my work if you want.

It's great that you push "editorconfig-netbeans" forward!

I don't know how much I'll be able to push the project forward since I have many other projects (including the Python plugin for NetBeans).

You can download older versions of the "editorconfig-netbeans" plugin from the Releases page to verify if the JSON formatting bug already existed.

I tried on 8.0.1 and 8.0.2: the indentation was not respected but the formatting of the file was not completely broken.

MimiXav commented 7 years ago

I confirm the bug on this, unfortunately, I don't see any fix on this?? Do you have a workaround ?

Thx

Regards

Jenselme commented 7 years ago

@MimiXav you can clone my fork git clone --branch netbeans-82 git@github.com:Jenselme/editorconfig-netbeans.git then build the NBMs from source with nvm clean install. Will be in target/editorconfig-0.10.1-SNAPSHOT.nbm.

MimiXav commented 7 years ago

Cool, I do this

MimiXav commented 7 years ago

Ok, I did, but unfortunately, My netbeans is freeze after a alt + shit + f ??? Do you have any idea? my netbeans is: Product Version: NetBeans IDE 8.2 (Build 201705191307)

Regards

Jenselme commented 7 years ago

I don't. I haven't used this plugin much yet.

What kind of project to you use?

MimiXav commented 7 years ago

Maven project, and java files

marcuscf commented 7 years ago

Is this plugin currently usable on the latest NetBeans 8.2 after all? I don't want to waste time downloading and installing (possibly multiple versions of) this plugin and finding that it doesn't work at all.

Jenselme commented 7 years ago

I'd say its unstable. You can build it from the source and install the resulting NBM as decribed previously. However, I experienced formatting errors while using it. So my recommendation is: wait until these issues are addressed and a proper release for 8.2 (or even 9.0) is made.

Chris2011 commented 6 years ago

Can someone of you please make a PR to fix this bug? Would be great.