Java Code Examples for org.netbeans.modules.maven.model.Utilities#performPOMModelOperations()

The following examples show how to use org.netbeans.modules.maven.model.Utilities#performPOMModelOperations() . 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: EAWizardIterator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates dependencies between EAR ---> Ejb module and EAR ---> Web module
 *
 * @param earDir ear module directory
 * @param ejbInfo ejb project informations
 * @param webInfo web project informations
 */
private void addEARDependencies(File earDir, ProjectInfo ejbInfo, ProjectInfo webInfo) {
    FileObject earDirFO = FileUtil.toFileObject(FileUtil.normalizeFile(earDir));
    if (earDirFO == null) {
        return;
    }
    List<ModelOperation<POMModel>> operations = new ArrayList<>();
    if (ejbInfo != null) {
        operations.add(ArchetypeWizards.addDependencyOperation(ejbInfo, "ejb")); // NOI18N
    }
    if (webInfo != null) {
        operations.add(ArchetypeWizards.addDependencyOperation(webInfo, "war")); // NOI18N
    }

    FileObject earPom = earDirFO.getFileObject("pom.xml"); // NOI18N
    if (earPom != null) {
        Utilities.performPOMModelOperations(earPom, operations);
    }
}
 
Example 3
Source File: MavenSchemaCompiler.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void compileSchema(final WizardDescriptor wiz) {
    final String schemaName = (String) wiz.getProperty(JAXBWizModuleConstants.SCHEMA_NAME);
    ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
        @Override
        public void performOperation(POMModel model) {
            org.netbeans.modules.maven.model.pom.Plugin plugin = addJaxb2Plugin(model); //NOI18N
            String packageName =
                    (String)wiz.getProperty(JAXBWizModuleConstants.PACKAGE_NAME);
            if (packageName != null && packageName.trim().length() == 0) {
                packageName = null;
            }
            addJaxb2Execution(plugin, schemaName, packageName);
        }
    };
    Utilities.performPOMModelOperations(project.getProjectDirectory().getFileObject("pom.xml"),
            Collections.singletonList(operation));
}
 
Example 4
Source File: HudsonProviderImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override boolean recordAssociation(Project p, final Association a) {
    FileObject pom = pom(p);
    if (pom == null) {
        return false;
    }
    Utilities.performPOMModelOperations(pom, Collections.<ModelOperation<POMModel>>singletonList(new ModelOperation<POMModel>() {
        public @Override void performOperation(POMModel model) {
            CiManagement cim;
            if (a != null) {
                cim = model.getFactory().createCiManagement();
                cim.setSystem(HUDSON_SYSTEM);
                cim.setUrl(a.toString());
            } else {
                cim = null;
            }
            model.getProject().setCiManagement(cim);
        }
    }));
    return true; // XXX pPOMMO does not rethrow exceptions or have a return value
}
 
Example 5
Source File: CPExtender.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean addLibrary(Library library) throws IOException {
    if ("toplink".equals(library.getName())) { //NOI18N
        //TODO would be nice if the toplink lib shipping with netbeans be the same binary
        // then we could just copy the pieces to local repo.
        //not necessary any more. toplink will be handled by default library impl..            
        // checking source doesn't work anymore, the wizard requires the level to be 1.5 up front.
        String source = PluginPropertyUtils.getPluginProperty(project, Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER, Constants.SOURCE_PARAM, "compile", "maven.compiler.source");
        if (source == null || source.matches("1[.][0-4]")) {
            Utilities.performPOMModelOperations(project.getProjectDirectory().getFileObject("pom.xml"), Collections.singletonList(new ModelOperation<POMModel>() {
                @Override public void performOperation(POMModel model) {
                    ModelUtils.setSourceLevel(model, SL_15);
                }
            }));
        }
    }
    //shall not return true, needs processing by the fallback impl as well.
    return false;
}
 
Example 6
Source File: MavenNbModuleImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    FileObject fo = project.getProjectDirectory().getFileObject("pom.xml"); //NOI18N
    final DependencyAdder monitor = this;
    ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
        @Override
        public void performOperation(POMModel model) {
            synchronized (monitor) {
                for (Dependency dep : toAdd) {
                    org.netbeans.modules.maven.model.pom.Dependency mdlDep =
                            ModelUtils.checkModelDependency(model, dep.getGroupId(), dep.getArtifactId(), true);
                    mdlDep.setVersion(dep.getVersion());
                    if (dep.getScope() != null) {
                        mdlDep.setScope(dep.getScope());
                    }
                }
                toAdd.clear();
            }
        }
    };
    Utilities.performPOMModelOperations(fo, Collections.singletonList(operation));
    project.getLookup().lookup(NbMavenProject.class).synchronousDependencyDownload();
}
 
Example 7
Source File: NetBeansRunParamsIDEChecker.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages({
    "# {0} - property name", "# {1} - pom.xml file", 
    "NetBeansRunParamsIDEChecker.msg_confirm=<html>New version of nbm-maven-plugin is available that doesn''t require pom.xml modification to debug or profile your project.<br>Upgrade to the new version of nbm-maven-plugin and remove the netbeans.run.params.ide property?",
    "NetBeansRunParamsIDEChecker.title_confirm=Upgrade nbm-maven-plugin to newer version",
    "NetBeansRunParamsIDEChecker.upgradeButton=Upgrade nbm-maven-plugin"
})
private static boolean removeInterpolation(File pom) {
    Object upgrade = NetBeansRunParamsIDEChecker_upgradeButton();
    Confirmation dd = new Confirmation(NetBeansRunParamsIDEChecker_msg_confirm(OLD_PROPERTY, pom), NetBeansRunParamsIDEChecker_title_confirm());
    dd.setOptions(new Object[] {upgrade, NotifyDescriptor.CANCEL_OPTION} );
    Object ret = DialogDisplayer.getDefault().notify(dd);
    if (ret != upgrade) {
        return true;
    }
    if (ret == upgrade) {
        Utilities.performPOMModelOperations(FileUtil.toFileObject(pom), 
                Arrays.<ModelOperation<POMModel>>asList(new ModelOperation[] { createUpgradePluginOperation(), createRemoveIdePropertyOperation()}));
        return false;
    }
    return false;
}
 
Example 8
Source File: NbmWizardIterator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void addModuleToApplication(File file, ProjectInfo nbm, Object object) {
    FileObject appPrjFO = FileUtil.toFileObject(FileUtil.normalizeFile(file));
    if (appPrjFO == null) {
        return;
    }
    List<ModelOperation<POMModel>> operations = new ArrayList<ModelOperation<POMModel>>();
    operations.add(ArchetypeWizards.addDependencyOperation(nbm, null));
    Utilities.performPOMModelOperations(appPrjFO.getFileObject("pom.xml"), operations);
}
 
Example 9
Source File: POMManager.java    From jeddict with Apache License 2.0 5 votes vote down vote up
@Override
public POMManager commit() {
    execute();
    if (operations.size() > 0) {
        Utilities.performPOMModelOperations(pomFileObject, operations);
    }
    pomModel.endTransaction();
    return this;
}
 
Example 10
Source File: POMManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void commit() {
    execute();
    if (operations.size() > 0) {
        Utilities.performPOMModelOperations(pomFileObject, operations);
    }
    pomModel.endTransaction();
}
 
Example 11
Source File: ModelUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param pom       FileObject that represents POM
 * @param group     
 * @param artifact
 * @param version
 * @param type
 * @param scope
 * @param classifier
 * @param acceptNull accept null values to scope,type and classifier.
 *                   If true null values will remove corresponding tag.
 */
public static void addDependency(FileObject pom,
        final String group,
        final String artifact,
        final String version,
        final String type,
        final String scope,
        final String classifier, final boolean acceptNull)
{
    ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
        private static final String BUNDLE_TYPE = "bundle"; //NOI18N
        @Override
        public void performOperation(POMModel model) {
            Dependency dep = checkModelDependency(model, group, artifact, true);
            dep.setVersion(version);
            if (acceptNull || scope != null) {
                dep.setScope(scope);
            }
            if (acceptNull || (type != null && !BUNDLE_TYPE.equals(type))) {
                dep.setType(type);
            }
            if (acceptNull || classifier != null) {
                dep.setClassifier(classifier);
            }
        }
    };
    Utilities.performPOMModelOperations(pom, Collections.singletonList(operation));
}
 
Example 12
Source File: ActivatorIterator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Set<DataObject> instantiate () throws IOException/*, IllegalStateException*/ {
    // Here is the default plain behavior. Simply takes the selected
    // template (you need to have included the standard second panel
    // in createPanels(), or at least set the properties targetName and
    // targetFolder correctly), instantiates it in the provided
    // position, and returns the result.
    // More advanced wizards can create multiple objects from template
    // (return them all in the result of this method), populate file
    // contents on the fly, etc.
   
    org.openide.filesystems.FileObject dir = Templates.getTargetFolder( wiz );
    DataFolder df = DataFolder.findFolder( dir );
    
    FileObject template = Templates.getTemplate( wiz );
    
    DataObject dTemplate = DataObject.find( template );                
    final DataObject dobj = dTemplate.createFromTemplate( df, Templates.getTargetName( wiz )  );

    //this part might be turned pluggable once we have also ant based osgi projects. if..
    Project project = Templates.getProject( wiz );
    ClassPath cp = ClassPath.getClassPath(dobj.getPrimaryFile(), ClassPath.SOURCE);
    final String path = cp.getResourceName(dobj.getPrimaryFile(), '.', false);

    final NbMavenProject prj = project.getLookup().lookup(NbMavenProject.class);
    if (prj != null) {
        Utilities.performPOMModelOperations(project.getProjectDirectory().getFileObject("pom.xml"),
                Collections.<ModelOperation<POMModel>>singletonList(
                    new ModelOperation<POMModel>() {
            @Override
                       public void performOperation(POMModel model) {
                           addActivator(prj, model, path);
                       }
                }
        ));
    }

    return Collections.singleton(dobj);
}
 
Example 13
Source File: ResourceImplTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testIncludes() throws Exception { // #198361
    FileObject pom = TestFileUtils.writeFile(FileUtil.toFileObject(getWorkDir()), "p0m.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");
    Utilities.performPOMModelOperations(pom, Collections.singletonList(new ModelOperation<POMModel>() {
        public @Override void performOperation(POMModel model) {
            Resource res = model.getFactory().createResource();
            res.setTargetPath("META-INF"); //NOI18N
            res.setDirectory("src"); //NOI18N
            res.addInclude("stuff/"); //NOI18N
            Build build = model.getFactory().createBuild();
            build.addResource(res);
            model.getProject().setBuild(build);
        }
    }));
    assertEquals("<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" +
            "    <build>\n" +
            "        <resources>\n" +
            "            <resource>\n" +
            "                <targetPath>META-INF</targetPath>\n" +
            "                <directory>src</directory>\n" +
            "                <includes>\n" +
            "                    <include>stuff/</include>\n" +
            "                </includes>\n" +
            "            </resource>\n" +
            "        </resources>\n" +
            "    </build>\n" +
            "</project>\n",
            pom.asText().replace("\r\n", "\n"));
}
 
Example 14
Source File: MavenTestNGSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages("remove_junit3_when_adding_testng=Removing JUnit 3.x dependency as TestNG has transitive dependency to JUnit 4.x.")
public void configureProject(FileObject createdFile) {
    ClassPath cp = ClassPath.getClassPath(createdFile, ClassPath.COMPILE);
    FileObject ng = cp.findResource("org.testng.annotations.Test"); //NOI18N
    if (ng == null) {
        final Project p = FileOwnerQuery.getOwner(createdFile);
        FileObject pom = p.getProjectDirectory().getFileObject("pom.xml"); //NOI18N
        ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
            public @Override
            void performOperation(POMModel model) {
                String groupID = "org.testng"; //NOI18N
                String artifactID = "testng"; //NOI18N
                if (!hasEffectiveDependency(groupID, artifactID, p.getLookup().lookup(NbMavenProject.class))) {
                    fixJUnitDependency(model, p.getLookup().lookup(NbMavenProject.class));
                    Dependency dep = ModelUtils.checkModelDependency(model, groupID, artifactID, true);
                    dep.setVersion("6.8.1"); //NOI18N
                    dep.setScope("test"); //NOI18N
                }
            }
        };
        Utilities.performPOMModelOperations(pom, Collections.singletonList(operation));
        RequestProcessor RP = new RequestProcessor("Configure TestNG project task", 1, true); //NOI18N
        RP.post(new Runnable() {

            public void run() {
                p.getLookup().lookup(NbMavenProject.class).downloadDependencyAndJavadocSource(true);
            }
        });
    }
}
 
Example 15
Source File: ModelUtilsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testAddModelRepository() throws Exception { // #212336
    FileObject pom = TestFileUtils.writeFile(FileUtil.toFileObject(getWorkDir()), "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");
    final MavenProject mp = ProjectManager.getDefault().findProject(pom.getParent()).getLookup().lookup(NbMavenProject.class).getMavenProject();
    Utilities.performPOMModelOperations(pom, Collections.singletonList(new ModelOperation<POMModel>() {
        @Override public void performOperation(POMModel model) {
            Repository added = ModelUtils.addModelRepository(mp, model, "http://repo1.maven.org/maven2/");
            assertNull(added);
            added = ModelUtils.addModelRepository(mp, model, "http://nowhere.net/maven2/");
            assertNotNull(added);
            added.setId("nowhere.net");
            added = ModelUtils.addModelRepository(mp, model, "http://nowhere.net/maven2/");
            assertNull(added);
        }
    }));
    assertEquals("<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"
            + "            <url>http://nowhere.net/maven2/</url>\n"
            // XXX would be nice to fix IdPOMComponentImpl to put <id> first
            + "            <id>nowhere.net</id>\n"
            + "        </repository>\n"
            + "    </repositories>\n"
            + "</project>\n",
            pom.asText().replace("\r\n", "\n"));
}
 
Example 16
Source File: OperationsImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void checkParentProject(FileObject projectDir, final boolean delete, final String newName, final String oldName) throws IOException {
    final String prjLoc = projectDir.getNameExt();
    FileObject fo = projectDir.getParent();
    Project possibleParent = ProjectManager.getDefault().findProject(fo);
    if (possibleParent != null) {
        final NbMavenProjectImpl par = possibleParent.getLookup().lookup(NbMavenProjectImpl.class);
        if (par != null) {
            FileObject pomFO = par.getProjectDirectory().getFileObject("pom.xml"); //NOI18N                
            if(pomFO != null) {
                ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {

                    @Override
                    public void performOperation(POMModel model) {
                        MavenProject prj = par.getOriginalMavenProject();
                        if ((prj.getModules() != null && prj.getModules().contains(prjLoc)) == delete) {
                            //delete/add module from/to parent..
                            if (delete) {
                                model.getProject().removeModule(prjLoc);
                            } else {
                                model.getProject().addModule(prjLoc);
                            }
                        }
                        if (newName != null && oldName != null) {
                            if (oldName.equals(model.getProject().getArtifactId())) {
                                // is this condition necessary.. why not just overwrite the artifactID always..
                                model.getProject().setArtifactId(newName);
                            }
                        }
                    }
                };
                Utilities.performPOMModelOperations(pomFO, Collections.singletonList(operation));
            } else {
                Logger.getLogger(OperationsImpl.class.getName()).log(Level.WARNING, "no pom found for a supposed project in {0}", par.getProjectDirectory());
            }
        }
    }
    
}
 
Example 17
Source File: RenameProjectPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void rename(Project parentProject, final String oldName, final String newName) {
    FileObject pomFO = parentProject.getProjectDirectory().getFileObject("pom.xml"); //NOI18N
    ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
        @Override
        public void performOperation(POMModel model) {
            List<String> modules = model.getProject().getModules();
            if (modules != null && modules.contains(oldName)) {
                //delete/add module from/to parent..
                model.getProject().removeModule(oldName);
                model.getProject().addModule(newName);
            }
        }
    };
    Utilities.performPOMModelOperations(pomFO, Collections.singletonList(operation));
}
 
Example 18
Source File: JaxWsNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void destroy() throws java.io.IOException {

    if (service.getLocalWsdl() != null) {           
        final String serviceId = service.getId();

        // remove execution from pom file
        ModelOperation<POMModel> oper = new ModelOperation<POMModel>() {
            @Override
            public void performOperation(POMModel model) {
                MavenModelUtils.removeWsimportExecution(model, serviceId);
            }
        };
        FileObject pom = project.getProjectDirectory().getFileObject("pom.xml"); //NOI18N
        Utilities.performPOMModelOperations(pom, Collections.singletonList(oper));

        // remove stale file
        try {
            removeStaleFile(serviceId);
        } catch (IOException ex) {
            Logger.getLogger(JaxWsClientNode.class.getName()).log(
                    Level.FINE, "Cannot remove stale file", ex); //NOI18N
        }
        //remove wsdl file
        FileObject wsdlFileObject = getLocalWsdl();
        JAXWSLightSupport jaxWsSupport = JAXWSLightSupport.getJAXWSLightSupport(implBeanClass);
        if (wsdlFileObject != null && jaxWsSupport != null) {
            // check if there are other clients/services with the same wsdl
            boolean hasOtherServices = false;
            List<JaxWsService> services = jaxWsSupport.getServices();
            for (JaxWsService s : services) {
                if (serviceId != null && !serviceId.equals(s.getId()) && service.getLocalWsdl().equals(s.getLocalWsdl())) {
                    hasOtherServices = true;
                    break;
                }
            }
            if (!hasOtherServices) {
                // remove wsdl file
                wsdlFileObject.delete();
            }
        }
    }

    WSUtils.removeImplClass(project, service.getImplementationClass());
}
 
Example 19
Source File: JaxWsClientCreator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void createClient() throws IOException {
    JAXWSLightSupport jaxWsSupport = JAXWSLightSupport.getJAXWSLightSupport(project.getProjectDirectory());
    String wsdlUrl = (String)wiz.getProperty(WizardProperties.WSDL_DOWNLOAD_URL);
    String filePath = (String)wiz.getProperty(WizardProperties.WSDL_FILE_PATH);
    //Boolean useDispatch = (Boolean) wiz.getProperty(ClientWizardProperties.USEDISPATCH);
    //if (wsdlUrl==null) wsdlUrl = "file:"+(filePath.startsWith("/")?filePath:"/"+filePath); //NOI18N
    if(wsdlUrl == null) {
        wsdlUrl = FileUtil.toFileObject(FileUtil.normalizeFile(new File(filePath))).getURL().toExternalForm();
    }
    FileObject localWsdlFolder = jaxWsSupport.getWsdlFolder(true);
    
    boolean hasSrcFolder = false;
    File srcFile = new File (FileUtil.toFile(project.getProjectDirectory()),"src"); //NOI18N
    if (srcFile.exists()) {
        hasSrcFolder = true;
    } else {
        hasSrcFolder = srcFile.mkdirs();
    }
    
    if (localWsdlFolder != null) {
        FileObject wsdlFo = retrieveWsdl(wsdlUrl, localWsdlFolder,
                hasSrcFolder);
        if (wsdlFo != null) {
            final boolean isJaxWsLibrary = MavenModelUtils.hasJaxWsAPI(project);
            final String relativePath = FileUtil.getRelativePath(localWsdlFolder, wsdlFo);
            final String clientName = wsdlFo.getName();

            Preferences prefs = ProjectUtils.getPreferences(project, MavenWebService.class, true);
            if (prefs != null) {
                // remember original wsdlUrl for Client
                prefs.put(MavenWebService.CLIENT_PREFIX+WSUtils.getUniqueId(wsdlFo.getName(), jaxWsSupport.getServices()), wsdlUrl);
            }

            if (!isJaxWsLibrary) {
                try {
                    MavenModelUtils.addMetroLibrary(project);
                    MavenModelUtils.addJavadoc(project);
                } catch (Exception ex) {
                    Logger.getLogger(
                        JaxWsClientCreator.class.getName()).log(
                            Level.INFO, "Cannot add Metro libbrary to pom file", ex); //NOI18N
                }
            }
            
            final String wsdlLocation = wsdlUrl;
            ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
                @Override
                public void performOperation(POMModel model) {

                    String packageName = (String) wiz.getProperty(WizardProperties.WSDL_PACKAGE_NAME);
                    org.netbeans.modules.maven.model.pom.Plugin plugin =
                            WSUtils.isEJB(project) ?
                                MavenModelUtils.addJaxWSPlugin(model, "2.0") : //NOI18N
                                MavenModelUtils.addJaxWSPlugin(model);

                    MavenModelUtils.addWsimportExecution(plugin, clientName, 
                            relativePath,wsdlLocation, packageName);
                    if (WSUtils.isWeb(project)) { // expecting web project
                        MavenModelUtils.addWarPlugin(model, true);
                    } else { // J2SE Project
                        MavenModelUtils.addWsdlResources(model);
                    }
                }
            };
            Utilities.performPOMModelOperations(project.getProjectDirectory().getFileObject("pom.xml"),
                    Collections.singletonList(operation));

            // execute wsimport goal
            RunConfig cfg = RunUtils.createRunConfig(FileUtil.toFile(
                    project.getProjectDirectory()),
                    project,
                    "JAX-WS:wsimport", //NOI18N
                    Collections.singletonList("compile")); //NOI18N
            
            RunUtils.executeMaven(cfg);
         }
    }
}
 
Example 20
Source File: ContainerCPModifierImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void extendClasspath(final FileObject file, final String[] symbolicNames) {
    if (symbolicNames == null) {
        return;
    }
    final Boolean[] added = new Boolean[1];
    added[0] = Boolean.FALSE;
    ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {

        @Override
        public void performOperation(POMModel model) {
            Map<String, Item> items = createItemList();
            ProjectSourcesClassPathProvider prv = project.getLookup().lookup(ProjectSourcesClassPathProvider.class);
            ClassPath[] cps = prv.getProjectClassPaths(ClassPath.COMPILE);
            ClassPath cp = ClassPathSupport.createProxyClassPath(cps);
            Profile version = Profile.JAVA_EE_5; //sort of fallback
            WebModule wm = WebModule.getWebModule(file);
            if (wm != null) {
                version = wm.getJ2eeProfile();
            } else {
                EjbJar ejb = EjbJar.getEjbJar(file);
                if (ejb != null) {
                    version = ejb.getJ2eeProfile();
                }
            }

            for (String name : symbolicNames) {
                Item item = items.get(name + ":" + version.toPropertiesString()); //NOI18N
                if (item != null) {
                    if (item.classToCheck != null) {
                        FileObject fo = cp.findResource(item.classToCheck);
                        if (fo != null) {
                            //skip, already on CP somehow..
                            continue;
                        }
                    }
                    Dependency dep = ModelUtils.checkModelDependency(model, item.groupId, item.artifactId, true);
                    dep.setVersion(item.version);
                    dep.setScope(Artifact.SCOPE_PROVIDED);
                    added[0] = Boolean.TRUE;
                } else {
                    LOGGER.log(Level.WARNING, "Cannot process api with symbolic name: {0}. Nothing will be added to project''s classpath.", name);
                }
            }
        }
    };
    FileObject pom = project.getProjectDirectory().getFileObject("pom.xml"); //NOI18N
    Utilities.performPOMModelOperations(pom, Collections.singletonList(operation));
    if (added[0]) {
        if (!SwingUtilities.isEventDispatchThread()) {
            project.getLookup().lookup(NbMavenProject.class).downloadDependencyAndJavadocSource(true);
        }
    }
}