예제 #1
0
  private boolean checkoutCode(
      final Launcher launcher, final FilePath workspace, final OutputStream logger)
      throws IOException, InterruptedException {
    final List<String> commands = new ArrayList<String>(4);

    debug.log(Level.INFO, "Checking out code in: " + workspace.getName());

    commands.add(getDescriptor().getExecutable());
    commands.add("init");
    commands.add("-u");
    commands.add(manifestRepositoryUrl);
    if (manifestBranch != null) {
      commands.add("-b");
      commands.add(manifestBranch);
    }
    if (manifestFile != null) {
      commands.add("-m");
      commands.add(manifestFile);
    }
    if (mirrorDir != null) {
      commands.add("--reference=" + mirrorDir);
    }
    if (repoUrl != null) {
      commands.add("--repo-url=" + repoUrl);
      commands.add("--no-repo-verify");
    }
    int returnCode = launcher.launch().stdout(logger).pwd(workspace).cmds(commands).join();
    if (returnCode != 0) {
      return false;
    }
    if (workspace != null) {
      FilePath rdir = workspace.child(".repo");
      FilePath lm = rdir.child("local_manifest.xml");
      lm.delete();
      if (localManifest != null) {
        if (localManifest.startsWith("<?xml")) {
          lm.write(localManifest, null);
        } else {
          URL url = new URL(localManifest);
          lm.copyFrom(url);
        }
      }
    }

    returnCode = doSync(launcher, workspace, logger);
    if (returnCode != 0) {
      debug.log(Level.WARNING, "Sync failed. Resetting repository");
      commands.clear();
      commands.add(getDescriptor().getExecutable());
      commands.add("forall");
      commands.add("-c");
      commands.add("git reset --hard");
      launcher.launch().stdout(logger).pwd(workspace).cmds(commands).join();
      returnCode = doSync(launcher, workspace, logger);
      if (returnCode != 0) {
        return false;
      }
    }
    return true;
  }
예제 #2
0
  @Override
  public void loadResultFile(int fileId, FilePath file) {
    InputStream responseBodyAsStream = null;
    try {
      URL url = new URL(String.format(this.serviceExchangeURL, this.sessionId, fileId));

      HttpClient client = new HttpClient();
      HttpMethod get = new GetMethod(url.toExternalForm());
      client.executeMethod(get);
      responseBodyAsStream = get.getResponseBodyAsStream();

      file.copyFrom(responseBodyAsStream);
    } catch (MalformedURLException e) {
      LOGGER.log(
          Level.SEVERE,
          "Cannot access to exchange service on SCTM. Check the service URL and if SCTM up and running.!",
          e);
    } catch (HttpException e) {
      // handle lost session here
    } catch (IOException e) {
      LOGGER.log(Level.SEVERE, "Cannot load result file from SCTM.", e);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      try {
        if (responseBodyAsStream != null) responseBodyAsStream.close();
      } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Cannot close file stream.", e);
      }
    }
  }
  private ArgumentListBuilder buildMavenCmdLine(
      AbstractBuild<?, ?> build, BuildListener listener, EnvVars env)
      throws IOException, InterruptedException {

    FilePath mavenHome = getMavenHomeDir(build, listener, env);

    if (!mavenHome.exists()) {
      listener.error("Couldn't find Maven home: " + mavenHome.getRemote());
      throw new Run.RunnerAbortedException();
    }

    ArgumentListBuilder args = new ArgumentListBuilder();

    FilePath mavenBootDir = new FilePath(mavenHome, "boot");
    FilePath[] classworldsCandidates = mavenBootDir.list("plexus-classworlds*.jar");
    if (classworldsCandidates == null || classworldsCandidates.length == 0) {
      listener.error("Couldn't find classworlds jar under " + mavenBootDir.getRemote());
      throw new Run.RunnerAbortedException();
    }

    FilePath classWorldsJar = classworldsCandidates[0];

    // classpath
    args.add("-classpath");
    // String cpSeparator = launcher.isUnix() ? ":" : ";";

    args.add(classWorldsJar.getRemote());

    // maven home
    args.addKeyValuePair("-D", "maven.home", mavenHome.getRemote(), false);

    String buildInfoPropertiesFile = env.get(BuildInfoConfigProperties.PROP_PROPS_FILE);
    boolean artifactoryIntegration = StringUtils.isNotBlank(buildInfoPropertiesFile);
    listener
        .getLogger()
        .println("Artifactory integration is " + (artifactoryIntegration ? "enabled" : "disabled"));
    String classworldsConfPath;
    if (artifactoryIntegration) {

      args.addKeyValuePair(
          "-D", BuildInfoConfigProperties.PROP_PROPS_FILE, buildInfoPropertiesFile, false);

      // use the classworlds conf packaged with this plugin and resolve the extractor libs
      File maven3ExtractorJar = Which.jarFile(Maven3BuildInfoLogger.class);
      FilePath actualDependencyDirectory =
          PluginDependencyHelper.getActualDependencyDirectory(build, maven3ExtractorJar);

      if (getMavenOpts() == null || !getMavenOpts().contains("-Dm3plugin.lib")) {
        args.addKeyValuePair("-D", "m3plugin.lib", actualDependencyDirectory.getRemote(), false);
      }

      URL classworldsResource =
          getClass()
              .getClassLoader()
              .getResource("org/jfrog/hudson/maven3/classworlds-freestyle.conf");

      File classworldsConfFile =
          new File(URLDecoder.decode(classworldsResource.getFile(), "utf-8"));
      if (!classworldsConfFile.exists()) {
        listener.error(
            "Unable to locate classworlds configuration file under "
                + classworldsConfFile.getAbsolutePath());
        throw new Run.RunnerAbortedException();
      }

      // If we are on a remote slave, make a temp copy of the customized classworlds conf
      if (Computer.currentComputer() instanceof SlaveComputer) {

        FilePath remoteClassworlds =
            build.getWorkspace().createTextTempFile("classworlds", "conf", "", false);
        remoteClassworlds.copyFrom(classworldsResource);
        classworldsConfPath = remoteClassworlds.getRemote();
      } else {
        classworldsConfPath = classworldsConfFile.getCanonicalPath();
      }
    } else {
      classworldsConfPath = new FilePath(mavenHome, "bin/m2.conf").getRemote();
    }

    args.addKeyValuePair("-D", "classworlds.conf", classworldsConfPath, false);

    // maven opts
    if (StringUtils.isNotBlank(getMavenOpts())) {
      String mavenOpts = Util.replaceMacro(getMavenOpts(), build.getBuildVariableResolver());
      args.add(mavenOpts);
    }

    // classworlds launcher main class
    args.add(CLASSWORLDS_LAUNCHER);

    // pom file to build
    String rootPom = getRootPom();
    if (StringUtils.isNotBlank(rootPom)) {
      args.add("-f", rootPom);
    }

    // maven goals
    args.addTokenized(getGoals());

    return args;
  }