List of usage examples for org.apache.maven.project MavenProject getArtifact
public Artifact getArtifact()
From source file:com.slim.service.BuildService.java
License:Apache License
public void buildear(MavenProject project, String outputDirectory, String archiveURI, String traHome, Log logger) throws MojoExecutionException { logger.info(" - BASE_DIR : " + project.getBasedir().toString()); logger.info(" - TRA_HOME : " + traHome); logger.info(" - OUTPUT_DIRECTORY : " + outputDirectory); try {/*from w ww . j av a 2 s . c om*/ CommandUtils.createDirectoryIfNeeded(project.getBasedir().toString() + "\\" + outputDirectory, logger); if (archiveURI == null || archiveURI.length() == 0) { archiveURI = "/" + project.getArtifact().getArtifactId(); } Map<String, String> options = new HashMap<String, String>(); options.put("-v", ""); options.put("-xs", ""); options.put(CommandUtils.EAR_OPTION, CommandUtils.GUILLEMETS + archiveURI + CommandUtils.GUILLEMETS); options.put(CommandUtils.PROJECT_OPTION, CommandUtils.GUILLEMETS + project.getBasedir().toString() + "\\" + project.getArtifact().getArtifactId() + CommandUtils.GUILLEMETS); options.put(CommandUtils.O_OPTION, CommandUtils.GUILLEMETS + project.getBasedir().toString() + "\\" + outputDirectory + "\\" + project.getArtifact().getArtifactId() + ".ear" + CommandUtils.GUILLEMETS); BufferedReader buildOutput = CommandUtils.executeCommand(logger, traHome, CommandUtils.getBuildEarBin(), options); boolean isError = false; StringBuffer result = new StringBuffer(); String line = null; while ((line = buildOutput.readLine()) != null) { if (line.contains("Error")) { isError = true; } result.append(line + "\n"); } if (isError) { logger.error(result.toString()); throw new Exception("Error in building ear ..."); } else { logger.info(result.toString()); } } catch (IOException e) { e.printStackTrace(); throw new MojoExecutionException("Error", e); } catch (Throwable e) { e.printStackTrace(); throw new MojoExecutionException("Error", e); } }
From source file:com.slim.service.DeployService.java
License:Apache License
/** * //from w w w .j a va2s .c o m * @param project * @param hostServer * @param hostUser * @param hostPassword * @param tibcoDomain * @param tibcoUser * @param tibcoPassword * @param outputDirectory * @param remoteDirectory * @throws MojoExecutionException */ public void deploy(MavenProject project, String hostServer, String hostUser, String hostPassword, String tibcoDomain, String tibcoUser, String tibcoPassword, String outputDirectory, String remoteDirectory, String appLocation, Log logger) throws MojoExecutionException { // TODO Check parameter try { String appTibco = appLocation == null || appLocation.trim().length() == 0 ? project.getArtifact().getArtifactId() : appLocation; String remotePath = remoteDirectory + "/" + appTibco; // Extrait le profil maven actuel String environnement = null; if (project.getActiveProfiles().size() > 0) { environnement = ((Profile) project.getActiveProfiles().get(0)).getId(); } else { environnement = CommandUtils.DFT; ; } String localEarFile = project.getBasedir().toString() + "\\" + outputDirectory + "\\" + project.getArtifact().getArtifactId() + CommandUtils.SUFFIXE_EAR; String localXmlFile = project.getBasedir().toString() + "\\" + outputDirectory + "\\" + environnement + "\\" + project.getArtifact().getArtifactId() + CommandUtils.SUFFIXE_XML; String remoteEarFile = remotePath + "/" + project.getArtifact().getArtifactId() + CommandUtils.SUFFIXE_EAR; String remoteXmlFile = remotePath + "/" + project.getArtifact().getArtifactId() + CommandUtils.SUFFIXE_XML; SSHClientUtils sshclient = new SSHClientUtils(hostServer, hostUser, hostPassword, logger); logger.info("Creating directory " + remotePath + " ..."); sshclient.sendShell("mkdir -p " + remotePath, remoteDirectory); logger.info("Moving " + localEarFile + " to " + remoteEarFile + " ..."); sshclient.sendFile(localEarFile, remoteEarFile); logger.info("Moving " + localXmlFile + " to " + remoteXmlFile + " ..."); sshclient.sendFile(localXmlFile, remoteXmlFile); StringBuilder commandDeploy = new StringBuilder(); commandDeploy.append(CommandUtils.getRemoteAppManageBin()).append(" -deploy"); commandDeploy.append(" -ear ").append(remoteEarFile); commandDeploy.append(" -deployconfig ").append(remoteXmlFile); commandDeploy.append(" -app ").append(appTibco); commandDeploy.append(" -domain ").append(tibcoDomain); commandDeploy.append(" -user ").append(tibcoUser); commandDeploy.append(" -pw ").append(tibcoPassword); logger.info("Executing " + commandDeploy.toString() + " ..."); sshclient.sendShell(commandDeploy.toString(), remoteDirectory); } catch (Exception e) { e.printStackTrace(); throw new MojoExecutionException("Error in deploying ear ..." + e.getMessage()); } }
From source file:com.slim.service.GenerateService.java
License:Apache License
public void generateXml(MavenProject project, String outputDirectory, String archiveURI, String traHome, Log logger) throws MojoExecutionException { CommandUtils.createDirectoryIfNeeded(project.getBasedir().toString() + "\\" + outputDirectory, logger); String outConfigurationFile = CommandUtils.GUILLEMETS + project.getBasedir().toString() + "\\" + outputDirectory + "\\" + project.getArtifact().getArtifactId() + ".xml" + CommandUtils.GUILLEMETS; String earFile = CommandUtils.GUILLEMETS + project.getBasedir().toString() + "\\" + outputDirectory + "\\" + project.getArtifact().getArtifactId() + ".ear" + CommandUtils.GUILLEMETS; logger.info(" - BASE_DIR : " + project.getBasedir().toString()); logger.info(" - TRA_HOME : " + traHome); logger.info(" - XML_CONFIG_LOCATION : " + outConfigurationFile); logger.info(" - EAR_LOCATION : " + earFile); try {/* w w w. java2s .c o m*/ if (archiveURI == null || archiveURI.length() == 0) { archiveURI = "/" + project.getArtifact().getArtifactId(); } Map<String, String> options = new HashMap<String, String>(); options.put(CommandUtils.EXPORT_OPTION, ""); options.put(CommandUtils.EAR_OPTION, earFile); options.put(CommandUtils.OUT_OPTION, outConfigurationFile); BufferedReader buildOutput = CommandUtils.executeCommand(logger, traHome, CommandUtils.getAppManageBin(), options); String line = null; while ((line = buildOutput.readLine()) != null) { // boolean ignored = false; logger.info(line); } } catch (IOException e) { e.printStackTrace(); throw new MojoExecutionException("Error", e); } catch (Throwable e) { e.printStackTrace(); throw new MojoExecutionException("Error", e); } }
From source file:com.slim.service.ReplaceService.java
License:Apache License
/** * // w w w. j av a 2 s . c om * @param project * @param outputDirectory * @param traHome * @param filterFile * @param machineTibco * @throws TransformerFactoryConfigurationError * @throws MojoFailureException */ public void replaceXml(MavenProject project, String outputDirectory, String traHome, String filterFile, String machineTibco, Log logger) throws TransformerFactoryConfigurationError, MojoFailureException { CommandUtils.createDirectoryIfNeeded(project.getBasedir().toString() + "\\" + outputDirectory, logger); String configFile = project.getBasedir().toString() + "\\" + outputDirectory + "\\" + project.getArtifact().getArtifactId() + CommandUtils.SUFFIXE_XML; String propertiesFile = project.getBasedir().toString() + "\\" + filterFile; logger.info(" - BASE_DIR : " + project.getBasedir().toString()); logger.info(" - TRA_HOME : " + traHome); logger.info(" - OUTPUT_DIRECTORY : " + outputDirectory); logger.info(" - CONFIG_FILE : " + configFile); logger.info(" - FILTER_FILE : " + propertiesFile); Map<String, String> mapAttribute = new HashMap<String, String>(); mapAttribute = parseFileProperties(propertiesFile, logger); Document doc = remplace(configFile, mapAttribute, machineTibco, logger); try { createFile(doc, outputDirectory, project, logger); } catch (TransformerException tfe) { logger.error(tfe.getMessage()); tfe.printStackTrace(); } }
From source file:com.slim.service.ReplaceService.java
License:Apache License
/** * //from w ww . j a v a 2 s . c o m * @param doc * @throws TransformerFactoryConfigurationError * @throws TransformerConfigurationException * @throws TransformerException */ private void createFile(Document doc, String outputDirectory, MavenProject project, Log logger) throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException { // Extrait le profil maven actuel String environnement = null; if (project.getActiveProfiles().size() > 0) { environnement = ((Profile) project.getActiveProfiles().get(0)).getId(); } else { environnement = CommandUtils.DFT; } // Write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); CommandUtils.createDirectoryIfNeeded( project.getBasedir().toString() + "\\" + outputDirectory + "\\" + environnement, logger); StreamResult result = new StreamResult(new File(project.getBasedir().toString() + "\\" + outputDirectory + "\\" + environnement + "\\" + project.getArtifact().getArtifactId() + CommandUtils.SUFFIXE_XML)); transformer.transform(source, result); }
From source file:com.slim.service.ValidateService.java
License:Apache License
/** * /*from ww w . j a v a 2 s . c om*/ * @param project * @param designerBinDir * @param outputDirectory * @param validationIgnoresFile * @param logger * @throws MojoExecutionException * @throws MojoFailureException */ public void validate(MavenProject project, String designerHome, String outputDirectory, String validationIgnoresFile, boolean checkUnusedGlobalVariables, Log logger) throws MojoExecutionException, MojoFailureException { String validateOutputFile = project.getBasedir().toString() + "\\" + outputDirectory + "\\" + "outValidate.txt"; logger.info(" - DESIGNER_HOME : " + designerHome); logger.info(" - BASE_DIR : " + project.getBasedir().toString()); logger.info(" - VALIDATE_OUTPUT_LOG : " + validateOutputFile); logger.info(" - IGNORE_FILE : " + validationIgnoresFile); boolean validated = true; Pattern pattern = preparePattern(project, designerHome, outputDirectory, validationIgnoresFile, logger); Pattern patternResult = Pattern.compile(".*Found.*errors.*and.*warnings.*"); try { CommandUtils.createDirectoryIfNeeded(project.getBasedir().toString() + "\\" + outputDirectory, logger); Map<String, String> options = new HashMap<String, String>(); if (checkUnusedGlobalVariables) { options.put(CommandUtils.U_OPTION, project.getBasedir().toString() + "\\" + project.getArtifact().getArtifactId()); } else { options.put(CommandUtils.STRING_VIDE, project.getBasedir().toString() + "\\" + project.getArtifact().getArtifactId()); } BufferedReader validateOutput = CommandUtils.executeCommand(logger, designerHome, CommandUtils.getValidateProjectBin(), options); BufferedWriter outLogStream = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(validateOutputFile))); outLogStream.append("#Log generated at " + new Date() + ".\n"); String line = null; while ((line = validateOutput.readLine()) != null) { boolean ignored = false; String trimmedLine = line.trim(); if (trimmedLine.length() == 0 || pattern.matcher(trimmedLine).matches()) { ignored = true; } if (!ignored) { validated = false; logger.warn(trimmedLine); } if (patternResult.matcher(line).matches()) { logger.info(line + "\n"); } outLogStream.append(line + "\n"); } outLogStream.close(); logger.info("*******************************************************************"); logger.info("Complete validation log is written to " + validateOutputFile); logger.info("*******************************************************************"); logger.info(""); } catch (IOException e) { e.printStackTrace(); throw new MojoExecutionException("Error", e); } catch (Throwable e) { e.printStackTrace(); throw new MojoExecutionException("Error", e); } if (!validated) { throw new MojoFailureException( "Project Validation failed ! Please check and verify Project or configure " + validationIgnoresFile); } }
From source file:com.sun.enterprise.module.maven.MavenProjectRepository.java
License:Open Source License
public MavenProjectRepository(MavenProject project, ArtifactResolver artifactResolver, ArtifactRepository localRepository, ArtifactFactory artifactFactory) { super(project.getName(), project.getFile().toURI()); this.project = project; this.artifactResolver = artifactResolver; this.localRepository = localRepository; this.artifactFactory = artifactFactory; // adds the ones that we already know of. Artifact ma = project.getArtifact(); if (ma.getFile() != null) { // if the 'ma' is the distribution module, it won't have its own output. artifacts.put(ma.getId(), ma);/*w ww . ja v a2s. c o m*/ } for (Artifact a : (Set<Artifact>) project.getArtifacts()) artifacts.put(a.getId(), a); }
From source file:com.sun.enterprise.module.maven.MavenProjectRepository.java
License:Open Source License
/** * When creating {@link MavenProjectRepository} from the current project (which is used * to launch mvn), and if the compile phase has run yet, then the main artifact is * still null.//from ww w . j a va 2 s . c o m * * <p> * However, it's often convenient to pick up the files that were left in the file system * from the previous execution. This method checks this situation and updates {@link MavenProject} * accordingly, so that it can be then passed to the constructor of {@link MavenProjectRepository}. * * <p> * Think of this as a pre-processing phase to compensate for the lack of the compile phase * invocation. */ public static void prepareProject(MavenProject project) throws IOException { Artifact ma = project.getArtifact(); if (!project.getPackaging().equals("pom") && ma.getFile() == null) { File outdir = new File(project.getBuild().getOutputDirectory()); if (!outdir.exists()) logger.warning("No output directory " + outdir); else ma.setFile(outdir); } if (ma.getFile() != null) { // if the 'ma' is the distribution module, it won't have its own output. if (ma.getFile().isDirectory()) { // if the main artifact is from target/classes, create META-INF.MF new Packager().writeManifest(project, ma.getFile()); } } }
From source file:com.synedge.enforcer.EnforceImportRelease.java
License:Apache License
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { Log log = helper.getLog();//ww w . j av a 2 s . c o m log.info("Entering enforcer"); try { // get the various expressions out of the helper. MavenProject project = (MavenProject) helper.evaluate("${project}"); if (project == null) { throw new EnforcerRuleException("There is no project"); } if (onlyWhenRelease && project.getArtifact().isSnapshot()) { log.warn("Project is SNAPSHOT, not validating"); return; } if (project.getDependencyManagement() == null) { log.info("No dependency management found. All ok"); return; } if (project.getDependencyManagement().getDependencies() == null) { log.info("No dependency management dependencies found. All ok"); return; } helper.getLog().debug("Getting POM, parse and check it"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file Document doc = db.parse(project.getFile().getAbsolutePath()); XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr = xpath.compile( "/*[local-name()='project']/*[local-name()='dependencyManagement']/*[local-name()='dependencies']/*[local-name()='dependency']/*[local-name()='scope' and text()='import']/../*[local-name()='version']"); NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); for (int i = 0; i < nl.getLength(); i++) { Node version = nl.item(i); if (version.getTextContent().contains("-SNAPSHOT")) { throw new EnforcerRuleException("Found an artifact in the import scope containing SNAPSHOT!"); } } helper.getLog().debug("Checked them all"); } catch (ExpressionEvaluationException e) { throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e); } catch (ParserConfigurationException e) { throw new EnforcerRuleException("Unable to parse POM", e); } catch (SAXException e) { throw new EnforcerRuleException("Unable to parse POM", e); } catch (IOException e) { throw new EnforcerRuleException("Unable to parse POM", e); } catch (XPathExpressionException e) { throw new EnforcerRuleException("Internal error in XPath parser", e); } }
From source file:com.taobao.hsf.jetty.RuntimeDependencyResolver.java
License:Apache License
/** * Download (if necessary) a pom, and load it as a MavenProject, transitively resolving any * dependencies therein./*from w ww .j a v a 2 s .c o m*/ * * @param projectBuilder * @param groupId * @param artifactId * @param versionId * @return a Set of Artifacts representing the transitively resolved dependencies. * * @throws MalformedURLException * @throws ProjectBuildingException * @throws InvalidDependencyVersionException * @throws ArtifactResolutionException * @throws ArtifactNotFoundException */ public Set transitivelyResolvePomDependencies(MavenProjectBuilder projectBuilder, String groupId, String artifactId, String versionId, boolean resolveProjectArtifact) throws MalformedURLException, ProjectBuildingException, InvalidDependencyVersionException, ArtifactResolutionException, ArtifactNotFoundException { Artifact pomArtifact = getPomArtifact(groupId, artifactId, versionId); MavenProject project = loadPomAsProject(projectBuilder, pomArtifact); List dependencies = project.getDependencies(); Set dependencyArtifacts = MavenMetadataSource.createArtifacts(artifactFactory, dependencies, null, null, null); dependencyArtifacts.add(project.getArtifact()); List listeners = Collections.EMPTY_LIST; if (PluginLog.getLog().isDebugEnabled()) { listeners = new ArrayList(); listeners.add(new RuntimeResolutionListener()); } ArtifactResolutionResult result = artifactResolver.resolveTransitively(dependencyArtifacts, pomArtifact, Collections.EMPTY_MAP, localRepository, remoteRepositories, metadataSource, null, listeners); Set artifacts = result.getArtifacts(); if (PluginLog.getLog().isDebugEnabled()) { PluginLog.getLog().debug("RESOLVED " + artifacts.size() + " ARTIFACTS"); Iterator itor = artifacts.iterator(); while (itor.hasNext()) { Artifact a = (Artifact) itor.next(); PluginLog.getLog().debug(a.getFile().toURL().toString()); } } return artifacts; }