Java Code Examples for org.netbeans.modules.maven.api.NbMavenProject#fireMavenProjectReload()

The following examples show how to use org.netbeans.modules.maven.api.NbMavenProject#fireMavenProjectReload() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OperationsImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void notifyMoved(Project original, File originalLoc, final String newName) throws IOException {
    if (original == null) {
        //old project call..
        project.getLookup().lookup(ProjectState.class).notifyDeleted();
    } else {
        if (original.getProjectDirectory().equals(project.getProjectDirectory())) {
            // oh well, just change the name in the pom when rename is invoked.
            FileObject pomFO = project.getProjectDirectory().getFileObject("pom.xml"); //NOI18N
            ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
                @Override
                public void performOperation(POMModel model) {
                    model.getProject().setName(newName);
                }
            };
            Utilities.performPOMModelOperations(pomFO, Collections.singletonList(operation));
            NbMavenProject.fireMavenProjectReload(project);
        }
        checkParentProject(project.getProjectDirectory(), false, newName, originalLoc.getName());
    }
}
 
Example 2
Source File: MavenSourceLevelImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testChanges() throws Exception {
    TestFileUtils.writeFile(wd, "pom.xml", "<project><modelVersion>4.0.0</modelVersion>"
            + "<groupId>test</groupId><artifactId>prj</artifactId>"
            + "<packaging>jar</packaging><version>1.0</version>"
            + "<build><plugins><plugin><artifactId>maven-compiler-plugin</artifactId><version>2.1</version>"
            + "<configuration><source>1.4</source></configuration></plugin></plugins></build>"
            + "</project>");
    FileObject source = TestFileUtils.writeFile(wd, "src/main/java/p/C.java", "package p; class C {}");
    SourceLevelQuery.Result r = SourceLevelQuery.getSourceLevel2(source);
    assertEquals("1.4", r.getSourceLevel());
    assertTrue(r.supportsChanges());
    MockChangeListener l = new MockChangeListener();
    r.addChangeListener(l);
    TestFileUtils.writeFile(wd, "pom.xml", "<project><modelVersion>4.0.0</modelVersion>"
            + "<groupId>test</groupId><artifactId>prj</artifactId>"
            + "<packaging>jar</packaging><version>1.0</version>"
            + "<build><plugins><plugin><artifactId>maven-compiler-plugin</artifactId><version>2.1</version>"
            + "<configuration><source>1.6</source></configuration></plugin></plugins></build>"
            + "</project>");
    NbMavenProject.fireMavenProjectReload(ProjectManager.getDefault().findProject(wd));
    l.expectEvent(9999);
    assertEquals("1.6", r.getSourceLevel());
}
 
Example 3
Source File: CPExtenderTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails // frequently fails in NB-Core-Build; [CPExtender] checkLibraryForPoms on Library[Stuff] -> true and [Utilities] WORKDIR/o.n.m.m.c.C/testAddRemovePomLib/pom.xml@1:2: CHILD_REMOVED:org.netbeans.modules.maven.model.pom.impl.ProjectImpl$PList@4 yet [Utilities] no changes in org.openide.loaders.XMLDataObject@c[WORKDIR/o.n.m.m.c.C/testAddRemovePomLib/pom.xml@1:2] where modified=true
public void testAddRemovePomLib() throws Exception {
    Library lib = LibraryManager.getDefault().createLibrary("j2se", "Stuff", Collections.singletonMap("maven-pom", Collections.singletonList(new URL("http://repo1.maven.org/maven2/grp/stuff/1.0/stuff-1.0.pom"))));
    Library lib2 = LibraryManager.getDefault().createLibrary("j2se", "Stuff2", Collections.singletonMap("maven-pom", Collections.singletonList(new URL("http://repo1.maven.org/maven2/grp/stuff/2.0/stuff-2.0.pom"))));
    FileObject d = FileUtil.toFileObject(getWorkDir());
    TestFileUtils.writeFile(d, "pom.xml", "<project><modelVersion>4.0.0</modelVersion>"
            + "<groupId>test</groupId><artifactId>prj</artifactId>"
            + "<packaging>jar</packaging><version>1.0</version></project>");
    FileObject java = TestFileUtils.writeFile(d, "src/main/java/p/C.java", "package p; class C {}");
    Project p = ProjectManager.getDefault().findProject(d);
    NbMavenProject mp = p.getLookup().lookup(NbMavenProject.class);
    assertEquals("[]", mp.getMavenProject().getDependencies().toString());
    assertTrue(ProjectClassPathModifier.addLibraries(new Library[] {lib}, java, ClassPath.COMPILE));
    assertFalse(ProjectClassPathModifier.addLibraries(new Library[] {lib}, java, ClassPath.COMPILE));
    NbMavenProject.fireMavenProjectReload(p); // XXX why is this necessary?
    assertEquals("[Dependency {groupId=grp, artifactId=stuff, version=1.0, type=jar}]", mp.getMavenProject().getDependencies().toString());
    assertFalse(ProjectClassPathModifier.removeLibraries(new Library[] {lib2}, java, ClassPath.COMPILE));
    assertTrue(ProjectClassPathModifier.removeLibraries(new Library[] {lib}, java, ClassPath.COMPILE));
    assertFalse(ProjectClassPathModifier.removeLibraries(new Library[] {lib}, java, ClassPath.COMPILE));
    NbMavenProject.fireMavenProjectReload(p);
    assertEquals("[]", mp.getMavenProject().getDependencies().toString());
}
 
Example 4
Source File: SelectAppServerPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void persistServer(Project project, final String iID, final String sID, final Project targetPrj) {
    JavaEEProjectSettings.setServerInstanceID(project, iID);
    MavenProjectSupport.setServerID(project, sID);

    // We want to initiate context path to default value if there isn't related deployment descriptor yet
    MavenProjectSupport.changeServer(project, true);

    // refresh all subprojects
    //TODO replace with DependencyProjectProvider or ProjectContainerProvider
    SubprojectProvider spp = targetPrj.getLookup().lookup(SubprojectProvider.class);
    //mkleint: we are assuming complete result (transitive projects included)
    //that's ok as far as the current maven impl goes afaik, but not according to the
    //documentation for SubProjectprovider
    Set<? extends Project> childrenProjs = spp.getSubprojects();
    if (!childrenProjs.contains(project)) {
        NbMavenProject.fireMavenProjectReload(project);
    }
    for (Project curPrj : childrenProjs) {
        NbMavenProject.fireMavenProjectReload(curPrj);
    }

}
 
Example 5
Source File: NbMavenProjectImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
        public void fileChanged(FileEvent fileEvent) {
                if (lastTime < fileEvent.getTime()) {
                    lastTime = System.currentTimeMillis();
//                    System.out.println("fired based on " + fileEvent.getFile() + fileEvent.getTime());
                    NbMavenProject.fireMavenProjectReload(NbMavenProjectImpl.this);
                }
        }
 
Example 6
Source File: NbMavenProjectImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
        public void fileDataCreated(FileEvent fileEvent) {
                if (lastTime < fileEvent.getTime()) {
                    lastTime = System.currentTimeMillis();
//                    System.out.println("fired based on " + fileEvent.getFile() + fileEvent.getTime());
                    NbMavenProject.fireMavenProjectReload(NbMavenProjectImpl.this);
                }
        }
 
Example 7
Source File: M2ConfigProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void setActiveConfiguration(M2Configuration configuration) throws IllegalArgumentException, IOException {
    M2Configuration _active;
    synchronized (this) {
        if (active == configuration || (active != null && active.equals(configuration))) {
            return;
        }
        _active = active;
    }
    doSetActiveConfiguration(configuration, _active);
    NbMavenProject.fireMavenProjectReload(project);
}
 
Example 8
Source File: RefreshAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override public void actionPerformed(ActionEvent event) {
    // #166919 - need to run in RP to prevent RPing later in fireProjectReload()
    //since #227101 fireMavenProjectReload() always posts to the RP... 
            //#211217 in 3.x should not be necessary.. 
            //EmbedderFactory.resetCachedEmbedders();
            for (NbMavenProjectImpl prj : context.lookupAll(NbMavenProjectImpl.class)) {
                NbMavenProject.fireMavenProjectReload(prj);
            }
}
 
Example 9
Source File: ModulesNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Messages("MSG_Remove_Module=Do you want to remove the module from the parent POM?")
@Override public void actionPerformed(ActionEvent e) {
    NotifyDescriptor nd = new NotifyDescriptor.Confirmation(MSG_Remove_Module(), NotifyDescriptor.YES_NO_OPTION);
    Object ret = DialogDisplayer.getDefault().notify(nd);
    if (ret == NotifyDescriptor.YES_OPTION) {
        FileObject fo = FileUtil.toFileObject(parent.getPOMFile());
        ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
            @Override
            public void performOperation(POMModel model) {
                List<String> modules = model.getProject().getModules();
                if (modules != null) {
                    for (String path : modules) {
                        File rel = new File(parent.getPOMFile().getParent(), path);
                        File norm = FileUtil.normalizeFile(rel);
                        FileObject folder = FileUtil.toFileObject(norm);
                        if (folder != null && folder.equals(project.getProjectDirectory())) {
                            model.getProject().removeModule(path);
                            break;
                        }
                    }
                }
            }
        };
        org.netbeans.modules.maven.model.Utilities.performPOMModelOperations(fo, Collections.singletonList(operation));
        //TODO is the manual reload necessary if pom.xml file is being saved?
        NbMavenProject.fireMavenProjectReload(project);
    }
}
 
Example 10
Source File: TransientRepositoriesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testListening() throws Exception {
    FileObject d = FileUtil.toFileObject(getWorkDir());
    TestFileUtils.writeFile(d, "pom.xml",
            "<project xmlns='http://maven.apache.org/POM/4.0.0'>\n"
            + "    <modelVersion>4.0.0</modelVersion>\n"
            + "    <groupId>grp</groupId>\n"
            + "    <artifactId>art</artifactId>\n"
            + "    <version>1.0</version>\n"
            + "</project>\n");
    Project p = ProjectManager.getDefault().findProject(d);
    TransientRepositories tr = new TransientRepositories(p.getLookup().lookup(NbMavenProject.class));
    assertRepos(CENTRAL_ANON);
    tr.register();
    assertRepos(CENTRAL_NAMED);
    TestFileUtils.writeFile(d, "pom.xml",
            "<project xmlns='http://maven.apache.org/POM/4.0.0'>\n"
            + "    <modelVersion>4.0.0</modelVersion>\n"
            + "    <groupId>grp</groupId>\n"
            + "    <artifactId>art</artifactId>\n"
            + "    <version>1.0</version>\n"
            + "    <repositories>\n"
            + "        <repository>\n"
            + "            <id>stuff</id>\n"
            + "            <name>Stuff</name>\n"
            + "            <url>http://nowhere.net/stuff</url>\n"
            + "        </repository>\n"
            + "    </repositories>\n"
            + "</project>\n");
    NbMavenProject.fireMavenProjectReload(p);
    assertRepos("stuff:Stuff:http://nowhere.net/stuff/", CENTRAL_NAMED);
    tr.unregister();
    assertRepos(CENTRAL_ANON);
}
 
Example 11
Source File: HudsonProviderImplTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testRecordAssociation() throws Exception {
    //synchronous reload of maven project asserts sanoty in some tests..
    System.setProperty("test.reload.sync", "true");        
    Project p = project(BASIC_PROJECT_START + BASIC_PROJECT_END);
    assertTrue(new HudsonProviderImpl().recordAssociation(p, new Association("http://nowhere.net/", "foo bar")));
    assertEquals(BASIC_PROJECT_START + " <ciManagement> <system>hudson</system> <url>http://nowhere.net/job/foo%20bar/</url> </ciManagement> " + BASIC_PROJECT_END,
            p.getProjectDirectory().getFileObject("pom.xml").asText().replaceAll("\\s+", " "));
    NbMavenProject.fireMavenProjectReload(p);
    assertEquals("http://nowhere.net/job/foo%20bar/", String.valueOf(new HudsonProviderImpl().findAssociation(p)));
}
 
Example 12
Source File: MicroApplication.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setRunning(boolean running) {
    if (running) {
        runActionCount.incrementAndGet();
    } else if (isRunning()) { // skip negative decrement
        runActionCount.decrementAndGet();
    }
    NbMavenProject.fireMavenProjectReload(project);
}
 
Example 13
Source File: MicroPluginWizardDescriptor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Set instantiate() throws IOException {
    String payaraMicroVersion = (String) descriptor.getProperty(PROP_PAYARA_MICRO_VERSION);
    String autoBindHttp = (String) descriptor.getProperty(PROP_AUTO_BIND_HTTP);
    String contextRoot = (String) descriptor.getProperty(PROP_CONTEXT_ROOT);

    updateMicroMavenPlugin(project, payaraMicroVersion, autoBindHttp, contextRoot);
    MicroApplication.registerInstance(project);
    new MicroProjectHook(project).projectOpened();
    NbMavenProject.fireMavenProjectReload(project);
    return Collections.emptySet();
}
 
Example 14
Source File: NbMavenProjectImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void fileDeleted(FileEvent fileEvent) {
        lastTime = System.currentTimeMillis();
        NbMavenProject.fireMavenProjectReload(NbMavenProjectImpl.this);
}
 
Example 15
Source File: MicroApplication.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setBuilding(boolean buildAction) {
    this.buildAction = buildAction;
    NbMavenProject.fireMavenProjectReload(project);
}
 
Example 16
Source File: MicroApplication.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setLoading(boolean loading) {
    this.reloadAction = loading;
    NbMavenProject.fireMavenProjectReload(project);
}