Пример #1
0
 public final void perform() throws Exception {
   VelocityConfigurator.config();
   VelocityContext ctx = new VelocityContext();
   try {
     MavenXpp3Reader reader = new MavenXpp3Reader();
     Model model = reader.read(new FileReader("pom.xml"));
     ctx.put("artifactId", model.getArtifactId());
     ctx.put("applicationName", model.getName());
     ctx.put("originalPomVersion", model.getVersion());
     ctx.put("originalBankaiVersion", model.getProperties().get("version.pt.ist.bankai"));
   } catch (FileNotFoundException e) {
     if (requiresMavenProject()) {
       LOG.error("Could not find pom.xml");
       LOG.error("Make sure you're in the project's root folder.");
       System.exit(-1);
     }
   }
   execute(ctx);
 }
 /**
  * Create the descriptor and set base information.
  *
  * @param model The model.
  * @param scanner The scanner.
  * @return The descriptor.
  */
 protected MavenPomDescriptor createMavenPomDescriptor(Model model, Scanner scanner) {
   ScannerContext context = scanner.getContext();
   MavenPomDescriptor pomDescriptor = context.peek(MavenPomDescriptor.class);
   pomDescriptor.setName(model.getName());
   pomDescriptor.setGroupId(model.getGroupId());
   pomDescriptor.setArtifactId(model.getArtifactId());
   pomDescriptor.setPackaging(model.getPackaging());
   pomDescriptor.setVersion(model.getVersion());
   String pomFqn = getFullyQualifiedName(model);
   pomDescriptor.setFullQualifiedName(pomFqn);
   Coordinates artifactCoordinates = new ModelCoordinates(model);
   MavenArtifactDescriptor artifact =
       getArtifactResolver(context).resolve(artifactCoordinates, context);
   // if the pom describes itself as artifact then the returned artifact
   // descriptor must be used as pom descriptor (the old instance is
   // invalidated due to adding labels)
   if (MavenPomDescriptor.class.isAssignableFrom(artifact.getClass())) {
     pomDescriptor = MavenPomDescriptor.class.cast(artifact);
   }
   pomDescriptor.getDescribes().add(artifact);
   return pomDescriptor;
 }
  private DefaultCoreExtension parseMavenPom(
      URL descriptorUrl, DefaultCoreExtensionRepository repository)
      throws IOException, XmlPullParserException {
    DefaultCoreExtension coreExtension = null;

    InputStream descriptorStream = descriptorUrl.openStream();
    try {
      MavenXpp3Reader reader = new MavenXpp3Reader();
      Model mavenModel = reader.read(descriptorStream);

      String version = resolveVersion(mavenModel.getVersion(), mavenModel, false);
      String groupId = resolveGroupId(mavenModel.getGroupId(), mavenModel, false);

      URL extensionURL = getExtensionURL(descriptorUrl);

      coreExtension =
          new MavenCoreExtension(
              repository,
              extensionURL,
              new ExtensionId(groupId + ':' + mavenModel.getArtifactId(), version),
              packagingToType(mavenModel.getPackaging()),
              mavenModel);

      coreExtension.setName(mavenModel.getName());
      coreExtension.setSummary(mavenModel.getDescription());
      for (Developer developer : mavenModel.getDevelopers()) {
        URL authorURL = null;
        if (developer.getUrl() != null) {
          try {
            authorURL = new URL(developer.getUrl());
          } catch (MalformedURLException e) {
            // TODO: log ?
          }
        }

        coreExtension.addAuthor(new DefaultExtensionAuthor(developer.getId(), authorURL));
      }
      coreExtension.setWebsite(mavenModel.getUrl());

      // licenses
      for (License license : mavenModel.getLicenses()) {
        coreExtension.addLicense(getExtensionLicense(license));
      }

      // features
      String featuresString = mavenModel.getProperties().getProperty("xwiki.extension.features");
      if (StringUtils.isNotBlank(featuresString)) {
        coreExtension.setFeatures(
            this.converter.<Collection<String>>convert(List.class, featuresString));
      }

      // custom properties
      coreExtension.putProperty("maven.groupId", groupId);
      coreExtension.putProperty("maven.artifactId", mavenModel.getArtifactId());

      // dependencies
      for (Dependency mavenDependency : mavenModel.getDependencies()) {
        if (!mavenDependency.isOptional()
            && (mavenDependency.getScope() == null
                || mavenDependency.getScope().equals("compile")
                || mavenDependency.getScope().equals("runtime"))) {

          String dependencyGroupId = resolveGroupId(mavenDependency.getGroupId(), mavenModel, true);
          String dependencyArtifactId = mavenDependency.getArtifactId();
          String dependencyClassifier = mavenDependency.getClassifier();
          String dependencyVersion = resolveVersion(mavenDependency.getVersion(), mavenModel, true);

          DefaultExtensionDependency extensionDependency =
              new MavenCoreExtensionDependency(
                  toExtensionId(dependencyGroupId, dependencyArtifactId, dependencyClassifier),
                  new DefaultVersionConstraint(dependencyVersion),
                  mavenDependency);

          coreExtension.addDependency(extensionDependency);
        }
      }
    } finally {
      IOUtils.closeQuietly(descriptorStream);
    }

    return coreExtension;
  }
  public MojoProjectStub(File projectDir) {
    this.basedir = projectDir;
    props.setProperty("basedir", this.basedir.getAbsolutePath());

    File pom = new File(getBasedir(), "plugin-config.xml");
    MavenXpp3Reader pomReader = new MavenXpp3Reader();
    Model model = null;
    FileReader fileReader = null;

    try {
      fileReader = new FileReader(pom);
      model = pomReader.read(fileReader);
      setModel(model);
    } catch (Exception e) {
      throw new RuntimeException(e);
    } finally {
      IOUtils.closeQuietly(fileReader);
    }

    setGroupId(model.getGroupId());
    setArtifactId(model.getArtifactId());
    setVersion(model.getVersion());
    setName(model.getName());
    setUrl(model.getUrl());
    setPackaging(model.getPackaging());
    setFile(pom);

    build = model.getBuild();
    if (build == null) {
      build = new Build();
    }

    File srcDir = getStandardDir(getBuild().getSourceDirectory(), "src/main/java");
    getBuild().setSourceDirectory(srcDir.getAbsolutePath());

    File targetDir = getStandardDir(getBuild().getDirectory(), "target");
    getBuild().setDirectory(targetDir.getAbsolutePath());

    File outputDir = getStandardDir(getBuild().getOutputDirectory(), "target/classes");
    getBuild().setOutputDirectory(outputDir.getAbsolutePath());

    List<Resource> resources = new ArrayList<Resource>();
    resources.addAll(getBuild().getResources());

    if (resources.isEmpty()) {
      resources = new ArrayList<Resource>();
      Resource resource = new Resource();
      File resourceDir = normalize("src/main/resources");
      resource.setDirectory(resourceDir.getAbsolutePath());
      makeDirs(resourceDir);
      resources.add(resource);
    } else {
      // Make this project work on windows ;-)
      for (Resource resource : resources) {
        File dir = normalize(resource.getDirectory());
        resource.setDirectory(dir.getAbsolutePath());
      }
    }

    getBuild().setResources(resources);
  }
  /**
   * Deploys with given Wagon (hint is provided), to deployUrl. It is caller matter to adjust those
   * two (ie. deployUrl with file: protocol to be deployed with file wagon would be error). Model is
   * supplied since it is read before.
   *
   * @param wagonHint
   * @param deployUrl
   * @param model
   * @throws Exception
   */
  protected void deployArtifacts(File project, String wagonHint, String deployUrl, Model model)
      throws Exception {
    log.info(
        "Deploying project \""
            + project.getAbsolutePath()
            + "\" using Wagon:"
            + wagonHint
            + " to URL=\""
            + deployUrl
            + "\".");

    // we already check if the pom.xml was in here.
    File pom = new File(project, "pom.xml");

    // FIXME, this needs to be fluffed up a little, should add the classifier, etc.
    String artifactFileName = model.getArtifactId() + "." + model.getPackaging();
    File artifactFile = new File(project, artifactFileName);

    log.debug("wow, this is working: " + artifactFile.getName());

    Gav gav =
        new Gav(
            model.getGroupId(),
            model.getArtifactId(),
            model.getVersion(),
            null,
            model.getPackaging(),
            0,
            new Date().getTime(),
            model.getName(),
            false,
            false,
            null,
            false,
            null);

    // the Restlet Client does not support multipart forms:
    // http://restlet.tigris.org/issues/show_bug.cgi?id=71

    // int status = DeployUtils.deployUsingPomWithRest( deployUrl, repositoryId, gav, artifactFile,
    // pom );

    if (!"pom".equals(model.getPackaging()) && !artifactFile.isFile()) {
      throw new FileNotFoundException(
          "File " + artifactFile.getAbsolutePath() + " doesn't exists!");
    }

    File artifactSha1 = new File(artifactFile.getAbsolutePath() + ".sha1");
    File artifactMd5 = new File(artifactFile.getAbsolutePath() + ".md5");
    File artifactAsc = new File(artifactFile.getAbsolutePath() + ".asc");

    File pomSha1 = new File(pom.getAbsolutePath() + ".sha1");
    File pomMd5 = new File(pom.getAbsolutePath() + ".md5");
    File pomAsc = new File(pom.getAbsolutePath() + ".asc");

    try {
      if (artifactSha1.exists()) {
        getDeployUtils()
            .deployWithWagon(
                wagonHint, deployUrl, artifactSha1, this.getRelitiveArtifactPath(gav) + ".sha1");
      }
      if (artifactMd5.exists()) {
        getDeployUtils()
            .deployWithWagon(
                wagonHint, deployUrl, artifactMd5, this.getRelitiveArtifactPath(gav) + ".md5");
      }
      if (artifactAsc.exists()) {
        getDeployUtils()
            .deployWithWagon(
                wagonHint, deployUrl, artifactAsc, this.getRelitiveArtifactPath(gav) + ".asc");
      }

      if (artifactFile.exists()) {
        getDeployUtils()
            .deployWithWagon(wagonHint, deployUrl, artifactFile, this.getRelitiveArtifactPath(gav));
      }

      if (pomSha1.exists()) {
        getDeployUtils()
            .deployWithWagon(wagonHint, deployUrl, pomSha1, this.getRelitivePomPath(gav) + ".sha1");
      }
      if (pomMd5.exists()) {
        getDeployUtils()
            .deployWithWagon(wagonHint, deployUrl, pomMd5, this.getRelitivePomPath(gav) + ".md5");
      }
      if (pomAsc.exists()) {
        getDeployUtils()
            .deployWithWagon(wagonHint, deployUrl, pomAsc, this.getRelitivePomPath(gav) + ".asc");
      }

      getDeployUtils().deployWithWagon(wagonHint, deployUrl, pom, this.getRelitivePomPath(gav));
    } catch (Exception e) {
      log.error(getTestId() + " Unable to deploy " + artifactFileName, e);
      throw e;
    }
  }