List of usage examples for org.apache.maven.project MavenProject getBasedir
public File getBasedir()
From source file:com.slim.service.DeployService.java
License:Apache License
/** * /*from w w w . j a va 2s.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 {//from w ww.jav a 2s. c om 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
/** * //from w ww . ja va 2 s . c o m * @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
/** * // ww w .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
/** * /*ww w. j a va2s . c o m*/ * @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.soebes.maven.extensions.incremental.ModuleCalculator.java
License:Apache License
/** * Calculate the modules which needed to be rebuilt based on the list of changes from SCM. * /* ww w .j a v a 2 s . co m*/ * @param projectRootpath Root path of the project. * @return The list of modules which needed to be rebuilt. */ public List<MavenProject> calculateChangedModules(Path projectRootpath) { // TODO: Think about if we got only pom packaging modules? Do we // need to do something special there? List<MavenProject> result = new ArrayList<>(); for (MavenProject project : projectList) { Path relativize = projectRootpath.relativize(project.getBasedir().toPath()); for (ScmFile fileItem : changeList) { boolean startsWith = new File(fileItem.getPath()).toPath().startsWith(relativize); logger.debug("startswith: " + startsWith + " " + fileItem.getPath() + " " + relativize); if (startsWith) { if (!result.contains(project)) { result.add(project); } } } } return result; }
From source file:com.techadvantage.tycho.extras.buildtimestamp.svnkit.SVNKitBuildTimestampProvider.java
License:Open Source License
public Date getTimestamp(MavenSession session, MavenProject project, MojoExecution execution) throws MojoExecutionException { DAVRepositoryFactory.setup();//from w w w. j a v a2 s . c o m SVNClientManager client = SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true), getLogin(execution), getPassword(execution)); try { return client.getWCClient().doInfo(project.getBasedir(), SVNRevision.BASE).getCommittedDate(); } catch (SVNException e) { // TODO Auto-generated catch block throw new MojoExecutionException("Could not determine svnkit commit timestamp", e); } }
From source file:com.topclouders.releaseplugin.mojo.ReleaseSiteGeneratorMojo.java
License:Apache License
/** * /* w ww. ja va 2 s . c o m*/ * @param mavenProject * @return * @throws MojoExecutionException */ private File getInputFile(MavenProject mavenProject) throws MojoExecutionException { File inputFile = new File(mavenProject.getBasedir(), this.inputFilePath); if (this.failOnMissingInputFile && (inputFile == null || !inputFile.exists())) { throw new MojoExecutionException("Input file %s does not exist for maven project %s", this.inputFilePath, mavenProject.getArtifactId()); } return inputFile; }
From source file:com.webguys.maven.plugin.st.Template.java
License:Open Source License
public void render(ST st, MavenProject project, Log log) throws MojoExecutionException { try {//from w w w .ja v a 2 s. c o m File outputFile = this.prepareOutputFile(project.getBasedir()); this.prepareCompilerSourceRoot(outputFile, project, log); FileWriter fileWriter = new FileWriter(outputFile); ErrorBuffer listener = new ErrorBuffer(); st.write(new AutoIndentWriter(fileWriter), listener); fileWriter.flush(); fileWriter.close(); if (!listener.errors.isEmpty()) { throw new MojoExecutionException(listener.toString()); } } catch (IOException e) { throw new MojoExecutionException(String.format("Unable to write output file: %s. (%s)", this.target.getAbsolutePath(), e.getMessage()), e); } }
From source file:de.akquinet.innovation.continuous.UniqueVersionMojo.java
License:Apache License
public void updateReleaseProperties(String newVersion) throws IOException { Properties properties = new Properties(); File releaseFile = new File(project.getBasedir(), "release.properties"); if (releaseFile.exists()) { FileInputStream fis = new FileInputStream(releaseFile); properties.load(fis);//from www . j a v a2 s . c o m IOUtils.closeQuietly(fis); } properties.put("scm.tag", project.getArtifactId() + "-" + newVersion); String oldVersion = project.getVersion(); // For all projects set: //project.rel.org.myCompany\:projectA=1.2 //project.dev.org.myCompany\:projectA=1.3-SNAPSHOT for (MavenProject project : reactor) { properties.put("project.rel." + project.getGroupId() + ":" + project.getArtifactId(), newVersion); properties.put("project.dev." + project.getGroupId() + ":" + project.getArtifactId(), oldVersion); } FileOutputStream fos = new FileOutputStream(releaseFile); properties.store(fos, "File edited by the continuous-version-maven-plugin"); IOUtils.closeQuietly(fos); }