List of usage examples for org.apache.maven.project MavenProject getPackaging
public String getPackaging()
From source file:org.jetbrains.maven.embedder.MavenEmbedder.java
License:Apache License
@SuppressWarnings({ "unchecked" }) private Map findArtifactTypeHandlers(MavenProject project) { // end copied from DefaultLifecycleExecutor.findExtensions Map result = new HashMap(); for (Object each : project.getBuildPlugins()) { Plugin eachPlugin = (Plugin) each; if (eachPlugin.isExtensions()) { try { PluginManager pluginManager = getComponent(PluginManager.class); pluginManager.verifyPlugin(eachPlugin, project, mySettings, myLocalRepository); result.putAll(pluginManager.getPluginComponents(eachPlugin, ArtifactHandler.ROLE)); } catch (Exception e) { MavenEmbedderLog.LOG.info(e); continue; }//from w w w . ja va2 s . co m for (Object o : result.values()) { ArtifactHandler handler = (ArtifactHandler) o; if (project.getPackaging().equals(handler.getPackaging())) { project.getArtifact().setArtifactHandler(handler); } } } } return result; }
From source file:org.jfrog.jade.plugins.idea.IdeaModuleMojo.java
License:Apache License
public void rewriteModule() throws MojoExecutionException { MavenProject executedProject = getExecutedProject(); File moduleFile = new File(executedProject.getBasedir(), getIdeProjectName() + ".iml"); try {//from w w w .j av a 2s. c om Document document = readXmlDocument(moduleFile, "module.xml"); Element module = document.getRootElement(); // TODO: how can we let the WAR/EJBs plugin hook in and provide this? // TODO: merge in ejb-module, etc. if ("war".equals(executedProject.getPackaging())) { addWebModule(module); } else if ("ejb".equals(executedProject.getPackaging())) { addEjbModule(module); } else if ("ear".equals(executedProject.getPackaging())) { addEarModule(module); } else if (isIdeaPlugin()) { addPluginModule(module); } Element component = findComponent(module, "NewModuleRootManager"); Element output = findElement(component, "output"); output.addAttribute("url", getModuleFileUrl(executedProject.getBuild().getOutputDirectory())); Element outputTest = findElement(component, "output-test"); outputTest.addAttribute("url", getModuleFileUrl(executedProject.getBuild().getTestOutputDirectory())); Element content = findElement(component, "content"); removeOldElements(content, "sourceFolder"); for (Iterator i = executedProject.getCompileSourceRoots().iterator(); i.hasNext();) { String directory = (String) i.next(); addSourceFolder(content, directory, false); } for (Iterator i = executedProject.getTestCompileSourceRoots().iterator(); i.hasNext();) { String directory = (String) i.next(); addSourceFolder(content, directory, true); } for (Iterator i = executedProject.getBuild().getResources().iterator(); i.hasNext();) { Resource resource = (Resource) i.next(); String directory = resource.getDirectory(); if (resource.getTargetPath() == null && !resource.isFiltering()) { addSourceFolder(content, directory, false); } else { getLog().info( "Not adding resource directory as it has an incompatible target path or filtering: " + directory); } } for (Iterator i = executedProject.getBuild().getTestResources().iterator(); i.hasNext();) { Resource resource = (Resource) i.next(); String directory = resource.getDirectory(); if (resource.getTargetPath() == null && !resource.isFiltering()) { addSourceFolder(content, directory, true); } else { getLog().info( "Not adding test resource directory as it has an incompatible target path or filtering: " + directory); } } removeOldElements(content, "excludeFolder"); //For excludeFolder File target = new File(executedProject.getBuild().getDirectory()); File classes = new File(executedProject.getBuild().getOutputDirectory()); File testClasses = new File(executedProject.getBuild().getTestOutputDirectory()); List sourceFolders = content.elements("sourceFolder"); List<String> filteredExcludes = new ArrayList<String>(); filteredExcludes.addAll(getExcludedDirectories(target, filteredExcludes, sourceFolders)); filteredExcludes.addAll(getExcludedDirectories(classes, filteredExcludes, sourceFolders)); filteredExcludes.addAll(getExcludedDirectories(testClasses, filteredExcludes, sourceFolders)); if (getExclude() != null) { String[] dirs = getExclude().split("[,\\s]+"); for (int i = 0; i < dirs.length; i++) { File excludedDir = new File(executedProject.getBasedir(), dirs[i]); filteredExcludes.addAll(getExcludedDirectories(excludedDir, filteredExcludes, sourceFolders)); } } // even though we just ran all the directories in the filteredExcludes List through the intelligent // getExcludedDirectories method, we never actually were guaranteed the order that they were added was // in the order required to make the most optimized exclude list. In addition, the smart logic from // that method is entirely skipped if the directory doesn't currently exist. A simple string matching // will do pretty much the same thing and make the list more concise. List<String> actuallyExcluded = new ArrayList<String>(); Collections.sort(filteredExcludes); for (Iterator i = filteredExcludes.iterator(); i.hasNext();) { String dirToExclude = i.next().toString(); String dirToExcludeTemp = dirToExclude.replace('\\', '/'); boolean addExclude = true; for (Iterator iterator = actuallyExcluded.iterator(); iterator.hasNext();) { String dir = iterator.next().toString(); String dirTemp = dir.replace('\\', '/'); if (dirToExcludeTemp.startsWith(dirTemp + "/")) { addExclude = false; break; } else if (dir.startsWith(dirToExcludeTemp + "/")) { actuallyExcluded.remove(dir); } } if (addExclude) { actuallyExcluded.add(dirToExclude); addExcludeFolder(content, dirToExclude); } } rewriteDependencies(component); writeXmlDocument(moduleFile, document); } catch (DocumentException e) { throw new MojoExecutionException("Error parsing existing IML file " + moduleFile.getAbsolutePath(), e); } catch (IOException e) { throw new MojoExecutionException("Error parsing existing IML file " + moduleFile.getAbsolutePath(), e); } }
From source file:org.jszip.maven.RunMojo.java
License:Apache License
public void execute() throws MojoExecutionException, MojoFailureException { if (runPackages == null || runPackages.length == 0) { runPackages = new String[] { "war" }; }//from www . j a v a2 s . c o m injectMissingArtifacts(project, executedProject); if (!Arrays.asList(runPackages).contains(project.getPackaging())) { getLog().info("Skipping JSZip run: module " + ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()) + " as not specified in runPackages"); return; } if (StringUtils.isNotBlank(runModule) && !project.getArtifactId().equals(runModule) && !ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()).equals(runModule)) { getLog().info("Skipping JSZip run: module " + ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()) + " as requested runModule is " + runModule); return; } getLog().info("Starting JSZip run: module " + ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId())); MavenProject project = this.project; long lastResourceChange = System.currentTimeMillis(); long lastClassChange = System.currentTimeMillis(); long lastPomChange = getPomsLastModified(); Server server = new Server(); if (connectors == null || connectors.length == 0) { SelectChannelConnector selectChannelConnector = new SelectChannelConnector(); selectChannelConnector.setPort(8080); connectors = new Connector[] { selectChannelConnector }; } server.setConnectors(connectors); ContextHandlerCollection contexts = new ContextHandlerCollection(); HandlerCollection handlerCollection = new HandlerCollection(true); DefaultHandler defaultHandler = new DefaultHandler(); handlerCollection.setHandlers(new Handler[] { contexts, defaultHandler }); server.setHandler(handlerCollection); try { server.start(); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } List<MavenProject> reactorProjects = this.reactorProjects; WebAppContext webAppContext; Resource webXml; List<Resource> resources; try { resources = new ArrayList<Resource>(); addCssEngineResources(project, reactorProjects, mappings, resources); for (Artifact a : getOverlayArtifacts(project, scope)) { addOverlayResources(reactorProjects, resources, a); } if (warSourceDirectory == null) { warSourceDirectory = new File(project.getBasedir(), "src/main/webapp"); } if (warSourceDirectory.isDirectory()) { resources.add(Resource.newResource(warSourceDirectory)); } Collections.reverse(resources); getLog().debug("Overlays:"); int index = 0; for (Resource r : resources) { getLog().debug(" [" + index++ + "] = " + r); } final ResourceCollection resourceCollection = new ResourceCollection( resources.toArray(new Resource[resources.size()])); webAppContext = new JettyWebAppContext(); webAppContext.setWar(warSourceDirectory.getAbsolutePath()); webAppContext.setBaseResource(resourceCollection); WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext); for (String s : getClasspathElements(project, scope)) { classLoader.addClassPath(s); } webAppContext.setClassLoader(classLoader); contexts.setHandlers(new Handler[] { webAppContext }); contexts.start(); webAppContext.start(); Resource webInf = webAppContext.getWebInf(); webXml = webInf != null ? webInf.getResource("web.xml") : null; } catch (MojoExecutionException e) { throw e; } catch (MojoFailureException e) { throw e; } catch (ArtifactFilterException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (MalformedURLException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } long webXmlLastModified = webXml == null ? 0L : webXml.lastModified(); try { getLog().info("Context started. Will restart if changes to poms detected."); long nextClasspathCheck = System.currentTimeMillis() + classpathCheckInterval; while (true) { long nextCheck = System.currentTimeMillis() + 500; long pomsLastModified = getPomsLastModified(); boolean pomsChanged = lastPomChange < pomsLastModified; boolean overlaysChanged = false; boolean classPathChanged = webXmlLastModified < (webXml == null ? 0L : webXml.lastModified()); if (nextClasspathCheck < System.currentTimeMillis()) { long classChange = classpathLastModified(project); if (classChange > lastClassChange) { classPathChanged = true; lastClassChange = classChange; } nextClasspathCheck = System.currentTimeMillis() + classpathCheckInterval; } if (!classPathChanged && !overlaysChanged && !pomsChanged) { try { lastResourceChange = processResourceSourceChanges(reactorProjects, project, lastResourceChange); } catch (ArtifactFilterException e) { getLog().debug("Couldn't process resource changes", e); } try { Thread.sleep(Math.max(100L, nextCheck - System.currentTimeMillis())); } catch (InterruptedException e) { getLog().debug("Interrupted", e); } continue; } if (pomsChanged) { getLog().info("Change in poms detected, re-parsing to evaluate impact..."); // we will now process this change, // so from now on don't re-process // even if we have issues processing lastPomChange = pomsLastModified; List<MavenProject> newReactorProjects; try { newReactorProjects = buildReactorProjects(); } catch (ProjectBuildingException e) { getLog().info("Re-parse aborted due to malformed pom.xml file(s)", e); continue; } catch (CycleDetectedException e) { getLog().info("Re-parse aborted due to dependency cycle in project model", e); continue; } catch (DuplicateProjectException e) { getLog().info("Re-parse aborted due to duplicate projects in project model", e); continue; } catch (Exception e) { getLog().info("Re-parse aborted due a problem that prevented sorting the project model", e); continue; } if (!buildPlanEqual(newReactorProjects, this.reactorProjects)) { throw new BuildPlanModifiedException("A pom.xml change has impacted the build plan."); } MavenProject newProject = findProject(newReactorProjects, this.project); if (newProject == null) { throw new BuildPlanModifiedException("A pom.xml change appears to have removed " + this.project.getId() + " from the build plan."); } newProject.setArtifacts(resolve(newProject, "runtime")); getLog().debug("Comparing effective classpath of new and old models"); try { classPathChanged = classPathChanged || classpathsEqual(project, newProject, scope); } catch (DependencyResolutionRequiredException e) { getLog().info("Re-parse aborted due to dependency resolution problems", e); continue; } if (classPathChanged) { getLog().info("Effective classpath of " + project.getId() + " has changed."); } else { getLog().debug("Effective classpath is unchanged."); } getLog().debug("Comparing effective overlays of new and old models"); try { overlaysChanged = overlaysEqual(project, newProject); } catch (OverConstrainedVersionException e) { getLog().info("Re-parse aborted due to dependency resolution problems", e); continue; } catch (ArtifactFilterException e) { getLog().info("Re-parse aborted due to overlay resolution problems", e); continue; } if (overlaysChanged) { getLog().info("Overlay modules of " + project.getId() + " have changed."); } else { getLog().debug("Overlay modules are unchanged."); } getLog().debug("Comparing overlays paths of new and old models"); try { List<Resource> newResources = new ArrayList<Resource>(); // TODO newMappings addCssEngineResources(newProject, newReactorProjects, mappings, resources); for (Artifact a : getOverlayArtifacts(project, scope)) { addOverlayResources(newReactorProjects, newResources, a); } if (warSourceDirectory.isDirectory()) { newResources.add(Resource.newResource(warSourceDirectory)); } Collections.reverse(newResources); getLog().debug("New overlays:"); int index = 0; for (Resource r : newResources) { getLog().debug(" [" + index++ + "] = " + r); } boolean overlayPathsChanged = !resources.equals(newResources); if (overlayPathsChanged) { getLog().info("Overlay module paths of " + project.getId() + " have changed."); } else { getLog().debug("Overlay module paths are unchanged."); } overlaysChanged = overlaysChanged || overlayPathsChanged; } catch (ArtifactFilterException e) { getLog().info("Re-parse aborted due to overlay evaluation problems", e); continue; } catch (PluginConfigurationException e) { getLog().info("Re-parse aborted due to overlay evaluation problems", e); continue; } catch (PluginContainerException e) { getLog().info("Re-parse aborted due to overlay evaluation problems", e); continue; } catch (IOException e) { getLog().info("Re-parse aborted due to overlay evaluation problems", e); continue; } project = newProject; reactorProjects = newReactorProjects; } if (!overlaysChanged && !classPathChanged) { continue; } getLog().info("Restarting context to take account of changes..."); try { webAppContext.stop(); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } if (classPathChanged) { getLog().info("Updating classpath..."); try { WebAppClassLoader classLoader = new WebAppClassLoader(webAppContext); for (String s : getClasspathElements(project, scope)) { classLoader.addClassPath(s); } webAppContext.setClassLoader(classLoader); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } } if (overlaysChanged || classPathChanged) { getLog().info("Updating overlays..."); try { resources = new ArrayList<Resource>(); addCssEngineResources(project, reactorProjects, mappings, resources); for (Artifact a : getOverlayArtifacts(project, scope)) { addOverlayResources(reactorProjects, resources, a); } if (warSourceDirectory.isDirectory()) { resources.add(Resource.newResource(warSourceDirectory)); } Collections.reverse(resources); getLog().debug("Overlays:"); int index = 0; for (Resource r : resources) { getLog().debug(" [" + index++ + "] = " + r); } final ResourceCollection resourceCollection = new ResourceCollection( resources.toArray(new Resource[resources.size()])); webAppContext.setBaseResource(resourceCollection); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } } try { webAppContext.start(); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } webXmlLastModified = webXml == null ? 0L : webXml.lastModified(); getLog().info("Context restarted."); } } finally { try { server.stop(); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } } }
From source file:org.kie.integration.eap.maven.util.EAPArtifactUtils.java
License:Apache License
public static Artifact createProjectArtifact(MavenProject project) { return EAPArtifactUtils.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging()); }
From source file:org.maven.ide.eclipse.wtp.RarPluginConfiguration.java
License:Open Source License
public RarPluginConfiguration(MavenProject mavenProject) { if (JEEPackaging.RAR != JEEPackaging.getValue(mavenProject.getPackaging())) throw new IllegalArgumentException("Maven project must have rar packaging"); this.rarProject = mavenProject; this.plugin = mavenProject.getPlugin("org.apache.maven.plugins:maven-rar-plugin"); }
From source file:org.metaeffekt.core.maven.kernel.MavenProjectUtil.java
License:Apache License
public static boolean isPomPackagingProject(MavenProject project) { validateProject(project);/*w w w . j a va 2s.c o m*/ return MAVEN_PACKAGING_POM.equalsIgnoreCase(project.getPackaging()); }
From source file:org.metaeffekt.core.maven.kernel.MavenProjectUtil.java
License:Apache License
public static boolean isJarPackagingProject(MavenProject project) { validateProject(project);// ww w .j av a 2 s. c o m return MAVEN_PACKAGING_JAR.equalsIgnoreCase(project.getPackaging()); }
From source file:org.mimacom.maven.plugins.liferay.BaseLiferayMojo.java
License:Apache License
protected boolean isPortalProject(MavenProject project) { return project.getPackaging().equals("liferayPortal"); }
From source file:org.mobicents.maven.plugin.eclipse.ClasspathWriter.java
License:Open Source License
/** * Writes the .classpath file for eclipse. * //from w w w.j a va 2 s . co m * @param projects * the list of projects from which the .classpath will get its * dependencies. * @param repositoryVariableName * the name of the maven repository variable. * @param artifactFactory * the factory for constructing artifacts. * @param artifactResolver * the artifact resolver. * @param localRepository * the local repository instance. * @param artifactMetadataSource * @param classpathArtifactTypes * the artifacts types that are allowed in the classpath file. * @param remoteRepositories * the list of remote repository instances. * @param resolveTransitiveDependencies * whether or not dependencies shall be transitively resolved. * @param merge * anything extra (not auto-generated), that should be "merged" * into the generated .classpath * @param classpathExcludes * @param includeTestsDirectory * @param includeResourcesDirectory * @throws Exception */ public void write(final List projects, final String repositoryVariableName, final ArtifactFactory artifactFactory, final ArtifactResolver artifactResolver, final ArtifactRepository localRepository, final ArtifactMetadataSource artifactMetadataSource, final Set classpathArtifactTypes, final List remoteRepositories, final boolean resolveTransitiveDependencies, final String merge, Set classpathExcludes, boolean includeResourcesDirectory) throws Exception { final String rootDirectory = PathNormalizer.normalizePath(this.project.getBasedir().toString()); final File classpathFile = new File(rootDirectory, ".classpath"); final FileWriter fileWriter = new FileWriter(classpathFile); final XMLWriter writer = new PrettyPrintXMLWriter(fileWriter, "UTF-8", null); writer.startElement("classpath"); final Set projectArtifactIds = new LinkedHashSet(); for (final Iterator iterator = projects.iterator(); iterator.hasNext();) { final MavenProject project = (MavenProject) iterator.next(); final Artifact projectArtifact = artifactFactory.createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, project.getPackaging()); projectArtifactIds.add(projectArtifact.getId()); } // - collect the source roots for the root project (if they are any) Set<String> sourceRoots = collectSourceRoots(this.project, rootDirectory, writer, includeResourcesDirectory); final Set allArtifacts = new LinkedHashSet(this.project.createArtifacts(artifactFactory, null, null)); for (final Iterator iterator = projects.iterator(); iterator.hasNext();) { final MavenProject project = (MavenProject) iterator.next(); sourceRoots.addAll(collectSourceRoots(project, rootDirectory, writer, includeResourcesDirectory)); final Set artifacts = project.createArtifacts(artifactFactory, null, null); // - get the direct dependencies for (final Iterator artifactIterator = artifacts.iterator(); artifactIterator.hasNext();) { final Artifact artifact = (Artifact) artifactIterator.next(); // - don't attempt to resolve the artifact if its part of the // project (we // infer this if it has the same id has one of the projects or // is in // the same groupId). if (!projectArtifactIds.contains(artifact.getId()) && !project.getGroupId().equals(artifact.getGroupId())) { artifactResolver.resolve(artifact, project.getRemoteArtifactRepositories(), localRepository); allArtifacts.add(artifact); } else { allArtifacts.add(artifact); } } } // we have all source roots now, sort and write for (String sourceRoot : sourceRoots) { logger.info("Adding src path " + sourceRoot); this.writeClasspathEntry(writer, "src", sourceRoot); } // - remove the project artifacts for (final Iterator iterator = projects.iterator(); iterator.hasNext();) { final MavenProject project = (MavenProject) iterator.next(); final Artifact projectArtifact = project.getArtifact(); if (projectArtifact != null) { for (final Iterator artifactIterator = allArtifacts.iterator(); artifactIterator.hasNext();) { final Artifact artifact = (Artifact) artifactIterator.next(); final String projectId = projectArtifact.getArtifactId(); final String projectGroupId = projectArtifact.getGroupId(); final String artifactId = artifact.getArtifactId(); final String groupId = artifact.getGroupId(); if (artifactId.equals(projectId) && groupId.equals(projectGroupId)) { artifactIterator.remove(); } } } } // - now we resolve transitively, if we have the flag on if (resolveTransitiveDependencies) { final Artifact rootProjectArtifact = artifactFactory.createArtifact(this.project.getGroupId(), this.project.getArtifactId(), this.project.getVersion(), null, this.project.getPackaging()); final OrArtifactFilter filter = new OrArtifactFilter(); filter.add(new ScopeArtifactFilter(Artifact.SCOPE_COMPILE)); filter.add(new ScopeArtifactFilter(Artifact.SCOPE_PROVIDED)); filter.add(new ScopeArtifactFilter(Artifact.SCOPE_TEST)); final ArtifactResolutionResult result = artifactResolver.resolveTransitively(allArtifacts, rootProjectArtifact, localRepository, remoteRepositories, artifactMetadataSource, filter); allArtifacts.clear(); allArtifacts.addAll(result.getArtifacts()); } // remove excluded ones for (Iterator i = allArtifacts.iterator(); i.hasNext();) { Artifact artifact = (Artifact) i.next(); if (classpathExcludes != null) { if (classpathExcludes.contains(artifact.getGroupId())) { logger.info("Excluding " + artifact + " from .classpath, groupId is excluded"); i.remove(); } else if (classpathExcludes.contains(artifact.getGroupId() + ":" + artifact.getArtifactId())) { logger.info("Excluding " + artifact + " from .classpath, groupId:artifactId is excluded"); i.remove(); } else if (classpathExcludes.contains( artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion())) { logger.info( "Excluding " + artifact + " from .classpath, groupId:artifactId:version is excluded"); i.remove(); } } } final List allArtifactPaths = new ArrayList(allArtifacts); for (final ListIterator iterator = allArtifactPaths.listIterator(); iterator.hasNext();) { final Artifact artifact = (Artifact) iterator.next(); if (classpathArtifactTypes.contains(artifact.getType())) { File artifactFile = artifact.getFile(); if (artifactFile == null) { artifactResolver.resolve(artifact, project.getRemoteArtifactRepositories(), localRepository); artifactFile = artifact.getFile(); } if (artifactFile != null) { final String path = StringUtils.replace(PathNormalizer.normalizePath(artifactFile.toString()), PathNormalizer.normalizePath(localRepository.getBasedir()), repositoryVariableName); iterator.set(path); } else { iterator.remove(); } } else { iterator.remove(); } } // - sort the paths Collections.sort(allArtifactPaths); for (final Iterator iterator = allArtifactPaths.iterator(); iterator.hasNext();) { String path = (String) iterator.next(); if (path.startsWith(repositoryVariableName)) { this.writeClasspathEntry(writer, "var", path); } else { if (path.startsWith(rootDirectory)) { path = StringUtils.replace(path, rootDirectory + '/', ""); } this.writeClasspathEntry(writer, "lib", path); } } this.writeClasspathEntry(writer, "con", "org.eclipse.jdt.launching.JRE_CONTAINER"); String outputPath = StringUtils.replace( PathNormalizer.normalizePath(this.project.getBuild().getOutputDirectory()), rootDirectory, ""); if (outputPath.startsWith("/")) { outputPath = outputPath.substring(1, outputPath.length()); } this.writeClasspathEntry(writer, "output", outputPath); if (StringUtils.isNotBlank(merge)) { writer.writeMarkup(merge); } writer.endElement(); logger.info("Classpath file written --> '" + classpathFile + "'"); IOUtil.close(fileWriter); }
From source file:org.openspaces.maven.plugin.RunPUMojo.java
License:Apache License
/** * Prepares and executes the PU./*from w w w .ja v a2 s. com*/ * * @throws MojoExecutionException * @throws MojoFailureException */ private void executePU(MavenProject project) throws MojoExecutionException, MojoFailureException { if (project == null || !project.getPackaging().equalsIgnoreCase("jar")) { throw new MojoExecutionException("The processing unit project '" + (project == null ? "unknown" : project.getName()) + "' must be of type jar (packaging=jar)."); } // run the PU PluginLog.getLog().info("Running processing unit: " + project.getBuild().getFinalName()); // resolve the classpath for the execution of the processing unit List classpath = null; ClassLoader classLoader = null; try { String[] includeScopes = Utils.convertCommaSeparatedListToArray(scopes); classpath = Utils.resolveExecutionClasspath(project, includeScopes, true, reactorProjects, dependencyTreeBuilder, metadataSource, artifactCollector, artifactResolver, artifactFactory, localRepository, remoteRepositories); PluginLog.getLog().info("Processing unit [" + project.getName() + "] classpath: " + classpath); classLoader = Utils.createClassLoader(classpath, null); } catch (Exception e1) { throw new MojoExecutionException("Failed to resolve the processing unit's classpath", e1); } // set groups if (groups != null && !groups.trim().equals("")) { SystemInfo.singleton().lookup().setGroups(groups); } // set locators if (locators != null && !locators.trim().equals("")) { SystemInfo.singleton().lookup().setLocators(locators); } // execute the processing unit in the new class loader ContainerRunnable conatinerRunnable = new ContainerRunnable( "org.openspaces.pu.container.integrated.IntegratedProcessingUnitContainer", createAttributesArray()); Thread thread = new Thread(conatinerRunnable, "Processing Unit [" + project.getBuild().getFinalName() + "]"); thread.setContextClassLoader(classLoader); thread.start(); while (!conatinerRunnable.hasStarted()) { try { Thread.sleep(200); } catch (InterruptedException e) { } } if (conatinerRunnable.getException() != null) { Utils.throwMissingLicenseException(conatinerRunnable.getException(), localRepository); throw new MojoExecutionException( "Failed to start processing unit [" + project.getBuild().getFinalName() + "]", conatinerRunnable.getException()); } containers.add(thread); }