コード例 #1
0
ファイル: SCMTrigger.java プロジェクト: nparry/jenkins
    private boolean runPolling() {
      try {
        // to make sure that the log file contains up-to-date text,
        // don't do buffering.
        StreamTaskListener listener = new StreamTaskListener(getLogFile());

        try {
          PrintStream logger = listener.getLogger();
          long start = System.currentTimeMillis();
          logger.println("Started on " + DateFormat.getDateTimeInstance().format(new Date()));
          boolean result = job.poll(listener).hasChanges();
          logger.println(
              "Done. Took " + Util.getTimeSpanString(System.currentTimeMillis() - start));
          if (result) logger.println("Changes found");
          else logger.println("No changes");
          return result;
        } catch (Error e) {
          e.printStackTrace(listener.error("Failed to record SCM polling"));
          LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
          throw e;
        } catch (RuntimeException e) {
          e.printStackTrace(listener.error("Failed to record SCM polling"));
          LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
          throw e;
        } finally {
          listener.close();
        }
      } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
        return false;
      }
    }
コード例 #2
0
  /** Called when a POST is made. */
  public void onPost(String triggeredByUser) {
    LOGGER.fine("Received POST by " + triggeredByUser);
    final String pushBy = triggeredByUser;
    if (triggerForUserCommit(triggeredByUser)) {
      LOGGER.fine("Triggering build " + triggeredByUser);
      getDescriptor()
          .queue
          .execute(
              new Runnable() {
                public void run() {
                  try {
                    StreamTaskListener listener = new StreamTaskListener(getLogFile());

                    try {
                      PrintStream logger = listener.getLogger();
                      long start = System.currentTimeMillis();
                      logger.println(
                          "Started on " + DateFormat.getDateTimeInstance().format(new Date()));
                      boolean result = job.poll(listener).hasChanges();
                      logger.println(
                          "Done. Took "
                              + Util.getTimeSpanString(System.currentTimeMillis() - start));
                      if (result) {
                        logger.println("Changes found");
                        job.scheduleBuild(new GitHubPushCause(pushBy));
                      } else {
                        logger.println("No changes");
                      }
                    } finally {
                      listener.close();
                    }
                  } catch (IOException e) {
                    LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e);
                  }
                }
              });
    } else {
      LOGGER.fine("ignoring commit by user " + triggeredByUser);
      try {
        StreamTaskListener listener = new StreamTaskListener(getLogFile());
        try {
          PrintStream logger = listener.getLogger();
          logger.println("ignoring commit by user " + triggeredByUser);
        } finally {
          listener.close();
        }
      } catch (IOException e) {
        LOGGER.log(Level.SEVERE, "Failed to record ignored commit", e);
      }
    }
  }
コード例 #3
0
  /** Fake installation on Unix. */
  @Test
  public void fakeUnixInstall() throws Exception {
    Assume.assumeFalse("If we're on Windows, don't bother doing this", Functions.isWindows());

    File bundle = File.createTempFile("fake-jdk-by-hudson", "sh");
    try {
      new FilePath(bundle)
          .write(
              "#!/bin/bash -ex\n"
                  + "mkdir -p jdk1.6.0_dummy/bin\n"
                  + "touch jdk1.6.0_dummy/bin/java",
              "ASCII");
      TaskListener l = StreamTaskListener.fromStdout();

      new JDKInstaller("", true)
          .install(
              new LocalLauncher(l),
              Platform.LINUX,
              new JDKInstaller.FilePathFileSystem(j.jenkins),
              l,
              tmp.getRoot().getPath(),
              bundle.getPath());

      assertTrue(new File(tmp.getRoot(), "bin/java").exists());
    } finally {
      bundle.delete();
    }
  }
コード例 #4
0
        @Override
        public void before() throws Throwable {
          super.before();

          content = new JellyScriptContent();
          listener = StreamTaskListener.fromStdout();

          publisher = new ExtendedEmailPublisher();
          publisher.defaultContent =
              "For only 10 easy payment of $69.99 , AWESOME-O 4000 can be yours!";
          publisher.defaultSubject = "How would you like your very own AWESOME-O 4000?";
          publisher.recipientList = "*****@*****.**";

          Field f = ExtendedEmailPublisherDescriptor.class.getDeclaredField("defaultBody");
          f.setAccessible(true);
          f.set(publisher.getDescriptor(), "Give me $4000 and I'll mail you a check for $40,000!");
          f = ExtendedEmailPublisherDescriptor.class.getDeclaredField("defaultSubject");
          f.setAccessible(true);
          f.set(publisher.getDescriptor(), "Nigerian needs your help!");

          f = ExtendedEmailPublisherDescriptor.class.getDeclaredField("recipientList");
          f.setAccessible(true);
          f.set(publisher.getDescriptor(), "*****@*****.**");

          f = ExtendedEmailPublisherDescriptor.class.getDeclaredField("hudsonUrl");
          f.setAccessible(true);
          f.set(publisher.getDescriptor(), "http://localhost/");

          build = mock(AbstractBuild.class);
          AbstractProject project = mock(AbstractProject.class);
          DescribableList publishers = mock(DescribableList.class);
          when(publishers.get(ExtendedEmailPublisher.class)).thenReturn(publisher);
          when(project.getPublishersList()).thenReturn(publishers);
          when(build.getProject()).thenReturn(project);
        }
コード例 #5
0
 @Before
 public void createGitRepository() throws IOException, InterruptedException {
   tempAllocator = new TemporaryDirectoryAllocator();
   testGitDir = tempAllocator.allocate();
   TaskListener listener = StreamTaskListener.fromStderr();
   testGitClient = Git.with(listener, new EnvVars()).in(testGitDir).getClient();
   testGitClient.init();
 }
コード例 #6
0
  /** Can we locate the bundles? */
  @Test
  public void locate() throws Exception {
    Assume.assumeTrue(
        "this is a really time consuming test, so only run it when we really want",
        Boolean.getBoolean("jenkins.testJDKInstaller"));

    retrieveUpdateCenterData();

    JDKInstaller i = new JDKInstaller("jdk-7u3-oth-JPR", true);
    StreamTaskListener listener = StreamTaskListener.fromStdout();
    i.locate(listener, Platform.LINUX, CPU.i386);
    i.locate(listener, Platform.WINDOWS, CPU.amd64);
    i.locate(listener, Platform.SOLARIS, CPU.Sparc);
  }
コード例 #7
0
 @Before
 public void setUp() throws Exception {
   try {
     listener = StreamTaskListener.fromStderr();
     File file = temporaryFolder.getRoot();
     testRepo = new TestIntegrityRepo("unnamed", file, listener);
     name1 = testRepo.userName1;
     name2 = testRepo.userName2;
     workDir = testRepo.IntegrityDir;
     workspace = testRepo.IntegrityDirPath;
   } catch (Throwable e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
  public BuildActionResultsDisplay getBuildActionResultsDisplay() {
    BuildActionResultsDisplay buildDisplay = null;
    WeakReference<BuildActionResultsDisplay> wr = this.buildActionResultsDisplay;
    if (wr != null) {
      buildDisplay = wr.get();
      if (buildDisplay != null) return buildDisplay;
    }

    try {
      buildDisplay = new BuildActionResultsDisplay(this, StreamTaskListener.fromStdout());
    } catch (IOException e) {
      logger.log(Level.SEVERE, "Error creating new BuildActionResultsDisplay()", e);
    }
    this.buildActionResultsDisplay = new WeakReference<BuildActionResultsDisplay>(buildDisplay);
    return buildDisplay;
  }
コード例 #9
0
ファイル: RunIdMigrator.java プロジェクト: sahumada/jenkins
 /** Inverse of {@link #doMigrate}. */
 private void unmigrateBuildsDir(File builds) throws Exception {
   File mapFile = new File(builds, MAP_FILE);
   if (!mapFile.isFile()) {
     System.err.println(builds + " does not look to have been migrated yet; skipping");
     return;
   }
   for (File build : builds.listFiles()) {
     int number;
     try {
       number = Integer.parseInt(build.getName());
     } catch (NumberFormatException x) {
       continue;
     }
     File buildXml = new File(build, "build.xml");
     if (!buildXml.isFile()) {
       System.err.println(buildXml + " did not exist");
       continue;
     }
     String xml = FileUtils.readFileToString(buildXml, Charsets.UTF_8);
     Matcher m = TIMESTAMP_ELT.matcher(xml);
     if (!m.find()) {
       System.err.println(buildXml + " did not contain <timestamp> as expected");
       continue;
     }
     long timestamp = Long.parseLong(m.group(1));
     String nl = m.group(2);
     xml = m.replaceFirst("  <number>" + number + "</number>" + nl);
     m = ID_ELT.matcher(xml);
     String id;
     if (m.find()) {
       id = m.group(1);
       xml = m.replaceFirst("");
     } else {
       // Post-migration build. We give it a new ID based on its timestamp.
       id = legacyIdFormatter.format(new Date(timestamp));
     }
     FileUtils.write(buildXml, xml, Charsets.UTF_8);
     if (!build.renameTo(new File(builds, id))) {
       System.err.println(build + " could not be renamed");
     }
     Util.createSymlink(builds, id, Integer.toString(number), StreamTaskListener.fromStderr());
   }
   Util.deleteFile(mapFile);
   System.err.println(builds + " has been restored to its original format");
 }
コード例 #10
0
 @Override
 public boolean processWorkspaceBeforeDeletion(
     AbstractProject<?, ?> project, FilePath workspace, Node node)
     throws IOException, InterruptedException {
   if (node == null) {
     // HUDSON-7663 : deleting a job that has never run
     return true;
   }
   StreamTaskListener listener = StreamTaskListener.fromStdout();
   Launcher launcher = node.createLauncher(listener);
   ClearTool ct =
       createClearTool(
           null,
           createClearToolLauncher(
               listener, project.getSomeWorkspace().getParent().getParent(), launcher));
   try {
     if (isUseDynamicView() && !isCreateDynView()) {
       return true;
     }
     AbstractBuild<?, ?> latestBuildOnNode = null;
     for (AbstractBuild<?, ?> build : project.getBuilds()) {
       if (node.equals(build.getBuiltOn())) {
         latestBuildOnNode = build;
         break;
       }
     }
     if (latestBuildOnNode == null) {
       latestBuildOnNode = project.getLastBuild();
     }
     BuildVariableResolver buildVariableResolver = new BuildVariableResolver(latestBuildOnNode);
     ct.rmviewtag(generateNormalizedViewName(buildVariableResolver));
   } catch (Exception e) {
     Logger.getLogger(AbstractClearCaseScm.class.getName())
         .log(Level.WARNING, "Failed to remove ClearCase view", e);
   }
   return true;
 }