/** * Prepares a command line argument object for use with the appclient exec task that uses the * default set of arguments: the default location and name for the retreived app client jar file. * * @param exec the ExecTask with which the command line should be associated * @return the argument, associated with the exec task, and set to invoke the gen'd app client */ protected Commandline.Argument prepareRunCommandlineArg(ExecTask exec) { Commandline.Argument arg = exec.createArg(); String archiveDir = project.getProperty("archivedir"); String testName = project.getProperty("testName"); arg.setLine("-client " + archiveDir + "/" + testName + "Client.jar"); return arg; }
/** Prepare the callable ant environment for the test. */ private void init() { if (!isInited()) { err = System.err; out = System.out; in = System.in; /* *Use the build.xml in the current directory. */ buildFile = new File("build.xml"); /* *To call into ant, create a new Project and prepare it for use. */ project = new Project(); // msgOutputLevel = Project.MSG_VERBOSE; project.addBuildListener(createLogger()); project.setBasedir("."); project.init(); /* *Set up the project to use the build.xml in the current directory. */ ProjectHelper helper = ProjectHelper.getProjectHelper(); helper.parse(project, buildFile); isInited = true; } }
/** * Executes the task. * * <p>Builds a command line to execute cleartool and then calls Exec's run method to execute the * command line. */ public void execute() throws BuildException { Commandline commandLine = new Commandline(); Project aProj = getProject(); int result = 0; // Check for required attributes if (getTypeName() == null) { throw new BuildException("Required attribute TypeName not specified"); } // Default the viewpath to basedir if it is not specified if (getViewPath() == null) { setViewPath(aProj.getBaseDir().getPath()); } // build the command line from what we got. the format is // cleartool mklabel [options...] [viewpath ...] // as specified in the CLEARTOOL help commandLine.setExecutable(getClearToolCommand()); commandLine.createArgument().setValue(COMMAND_MKLABEL); checkOptions(commandLine); result = run(commandLine); if (Execute.isFailure(result)) { String msg = "Failed executing: " + commandLine.toString(); throw new BuildException(msg, location); } }
/** * Executes the task. * * <p>Builds a command line to execute cleartool and then calls Exec's run method to execute the * command line. * * @throws BuildException if the command fails and failonerr is set to true */ public void execute() throws BuildException { Commandline commandLine = new Commandline(); Project aProj = getProject(); int result = 0; // Default the viewpath to basedir if it is not specified if (getViewPath() == null) { setViewPath(aProj.getBaseDir().getPath()); } // build the command line from what we got the format is // cleartool lock [options...] // as specified in the CLEARTOOL.EXE help commandLine.setExecutable(getClearToolCommand()); commandLine.createArgument().setValue(COMMAND_UNLOCK); // Check the command line options checkOptions(commandLine); // For debugging // System.out.println(commandLine.toString()); if (!getFailOnErr()) { getProject().log("Ignoring any errors that occur for: " + getOpType(), Project.MSG_VERBOSE); } result = run(commandLine); if (Execute.isFailure(result) && getFailOnErr()) { String msg = "Failed executing: " + commandLine.toString(); throw new BuildException(msg, getLocation()); } }
/** Instantiates the identified custom selector class. */ public void selectorCreate() { if (classname != null && classname.length() > 0) { try { Class c = null; if (classpath == null) { c = Class.forName(classname); } else { // Memory-Leak in line below AntClassLoader al = getProject().createClassLoader(classpath); c = Class.forName(classname, true, al); } dynselector = (FileSelector) c.newInstance(); final Project p = getProject(); if (p != null) { p.setProjectReference(dynselector); } } catch (ClassNotFoundException cnfexcept) { setError("Selector " + classname + " not initialized, no such class"); } catch (InstantiationException iexcept) { setError("Selector " + classname + " not initialized, could not create class"); } catch (IllegalAccessException iaexcept) { setError("Selector " + classname + " not initialized, class not accessible"); } } else { setError("There is no classname specified"); } }
public static void executeTestFile(File baseDir, File releaseTestFile, TestReport testReport) throws IOException { String testDataDirectory = releaseTestFile.getParent(); info(""); info("---------------------------------------------------------------"); info("Lancement du test release : " + releaseTestFile.getAbsolutePath()); info("\tRepertoire des donnees du test : " + testDataDirectory); info("\tRepertoire de lancement : " + baseDir); // Surcharge du comportement de ANT System.setProperty("test.dir", testDataDirectory); System.setProperty("basedir", baseDir.getAbsolutePath()); // Lancement du test try { Project project = new Project(); project.addBuildListener(new TokioLoadListener(testReport)); project.addBuildListener(new TokioInsertListener(testReport)); AntRunner.start(project, new AntGenerator().generateAntFile(releaseTestFile)); } catch (IOException e) { error("[TEST EN ECHEC :: " + releaseTestFile.getName() + "]", e); throw e; } finally { System.clearProperty("test.dir"); System.clearProperty("basedir"); } }
public boolean perform(Build build, Launcher launcher, BuildListener listener) { // this is where you 'build' the project // since this is a dummy, we just say 'hello world' and call that a build // this also shows how you can consult the global configuration of the builder if (DESCRIPTOR.useFrench()) listener.getLogger().println("Bonjour, " + name + "!"); else listener.getLogger().println("Hello, " + name + "!"); listener.getLogger().println("START"); Project project = new HelloAntProject(); project.init(); BuildLogger logger = new DefaultLogger(); logger.setMessageOutputLevel(Project.MSG_INFO); logger.setOutputPrintStream(new java.io.PrintStream(System.out)); logger.setErrorPrintStream(new java.io.PrintStream(System.err)); logger.setEmacsMode(false); // project.addBuildListener((org.apache.tools.ant.BuildListener) listener); project.addBuildListener(logger); java.util.Vector list = new java.util.Vector(); /* * ターゲットを指定 list.add("compile"); のようにすれば任意のターゲットを指定できます。 */ list.add(project.getDefaultTarget()); // project.executeTargets(new java.util.Vector(list)); listener.getLogger().println("DONE"); return true; }
@Override public void execute() throws BuildException { if (port <= 0) { throw new BuildException("Port must be set to a positive integer"); } if (scripts == null && script == null) { throw new BuildException("Scripts must be specified as an embedded resource collection"); } if (scripts != null && script != null) { throw new BuildException( "Scripts can be specified either by the script attribute or as resource collections but not both."); } for (AddUser user : users) { user.validate(); } if (skip) { log("Skipping excution"); } else if (errorProperty == null) { doExecute(); } else { try { doExecute(); } catch (BuildException e) { final Project project = getProject(); project.setProperty(errorProperty, e.getMessage()); log(e, Project.MSG_DEBUG); } } }
/** tests the failure of a task within a parallel construction */ public void testFail() { // should get no output at all Project p = getProject(); p.setUserProperty("test.failure", FAILURE_MESSAGE); p.setUserProperty("test.delayed", DELAYED_MESSAGE); expectBuildExceptionContaining("testFail", "fail task in one parallel branch", FAILURE_MESSAGE); }
/** * Returns a fully configured FileNameMapper implementation. * * @return a FileNameMapper object to be configured * @throws BuildException on error */ public FileNameMapper getImplementation() throws BuildException { if (isReference()) { return getRef().getImplementation(); } if (type == null && classname == null && container == null) { throw new BuildException( "nested mapper or " + "one of the attributes type or classname is required"); } if (container != null) { return container; } if (type != null && classname != null) { throw new BuildException("must not specify both type and classname attribute"); } try { FileNameMapper m = (FileNameMapper) (getImplementationClass().newInstance()); final Project p = getProject(); if (p != null) { p.setProjectReference(m); } m.setFrom(from); m.setTo(to); return m; } catch (BuildException be) { throw be; } catch (Throwable t) { throw new BuildException(t); } }
public void execute() throws BuildException { log("loading hibernate properties from " + config); Configuration configuration = AntHelper.getConfiguration(config, null); Properties properties = configuration.getProperties(); if (properties.isEmpty()) return; StringBuffer nameBuf = new StringBuffer(prefix); int prefixLength = prefix.length(); Project project = getProject(); for (Iterator i = properties.entrySet().iterator(); i.hasNext(); ) { Map.Entry property = (Entry) i.next(); String name = (String) property.getKey(); if (include(name) && !exclude(name)) { name = nameBuf.append(name).toString(); String value = (String) property.getValue(); log("setting '" + name + "' to: " + value); project.setNewProperty(name, value); // drop key from prefix nameBuf.setLength(prefixLength); } } }
/** @throws Exception If failed. */ public void testAntGarTaskToString() throws Exception { String tmpDirName = GridTestProperties.getProperty("ant.gar.tmpdir"); String srcDirName = GridTestProperties.getProperty("ant.gar.srcdir"); String baseDirName = tmpDirName + File.separator + System.currentTimeMillis() + "_6"; String metaDirName = baseDirName + File.separator + "META-INF"; String garFileName = baseDirName + ".gar"; // Make base and META-INF dir. boolean mkdir = new File(baseDirName).mkdirs(); assert mkdir; mkdir = new File(metaDirName).mkdirs(); assert mkdir; // Copy files to basedir U.copy(new File(srcDirName), new File(baseDirName), true); IgniteDeploymentGarAntTask garTask = new IgniteDeploymentGarAntTask(); Project garProject = new Project(); garProject.setName("Gar test project"); garTask.setDestFile(new File(garFileName)); garTask.setBasedir(new File(garFileName)); garTask.setProject(garProject); garTask.setDescrdir(new File(garFileName)); garTask.toString(); }
/** * Checks if the file paths in the md5sums file use only unix file separators (this test can only * fail on Windows) */ public void testBuildDataWithFileSet() throws Exception { Processor processor = new Processor( new Console() { public void println(String s) {} }, null); Project project = new Project(); project.setCoreLoader(getClass().getClassLoader()); project.init(); FileSet fileset = new FileSet(); fileset.setDir(new File(getClass().getResource("deb/data").toURI())); fileset.setIncludes("**/*"); fileset.setProject(project); StringBuffer md5s = new StringBuffer(); processor.buildData( new DataProducer[] {new FileSetDataProducer(fileset)}, new File("target/data.tar"), md5s, "tar"); assertTrue("empty md5 file", md5s.length() > 0); assertFalse("windows path separator found", md5s.indexOf("\\") != -1); }
/** * Get Current Connection from <em>ref</em> parameter or create a new one! * * @return The server connection * @throws MalformedURLException * @throws IOException */ @SuppressWarnings("null") public static MBeanServerConnection accessJMXConnection( Project project, String url, String host, String port, String username, String password, String refId) throws MalformedURLException, IOException { MBeanServerConnection jmxServerConnection = null; boolean isRef = project != null && refId != null && refId.length() > 0; if (isRef) { Object pref = project.getReference(refId); try { jmxServerConnection = (MBeanServerConnection) pref; } catch (ClassCastException cce) { project.log("wrong object reference " + refId + " - " + pref.getClass()); return null; } } if (jmxServerConnection == null) { jmxServerConnection = createJMXConnection(url, host, port, username, password); } if (isRef && jmxServerConnection != null) { project.addReference(refId, jmxServerConnection); } return jmxServerConnection; }
private void setDefaultInputStream(GantBinding binding) { // Gant does not initialise the default input stream for // the Ant project, so we manually do it here. AntBuilder antBuilder = (AntBuilder) binding.getVariable("ant"); Project p = antBuilder.getAntProject(); try { System.setIn(originalIn); p.setInputHandler(new CommandLineInputHandler()); p.setDefaultInputStream(originalIn); } catch (NoSuchMethodError nsme) { // will only happen due to a bug in JRockit // note - the only approach that works is to loop through the public methods for (Method m : p.getClass().getMethods()) { if ("setDefaultInputStream".equals(m.getName()) && m.getParameterTypes().length == 1 && InputStream.class.equals(m.getParameterTypes()[0])) { try { m.invoke(p, originalIn); break; } catch (Exception e) { // shouldn't happen, but let it bubble up to the catch(Throwable) throw new RuntimeException(e); } } } } }
public RepositorySystemSession getSession(Task task, LocalRepository localRepo) { DefaultRepositorySystemSession session = new MavenRepositorySystemSession(); Map<Object, Object> configProps = new LinkedHashMap<Object, Object>(); configProps.put(ConfigurationProperties.USER_AGENT, getUserAgent()); configProps.putAll(System.getProperties()); configProps.putAll((Map<?, ?>) project.getProperties()); configProps.putAll((Map<?, ?>) project.getUserProperties()); session.setConfigProps(configProps); session.setNotFoundCachingEnabled(false); session.setTransferErrorCachingEnabled(false); session.setOffline(isOffline()); session.setUserProps(project.getUserProperties()); session.setLocalRepositoryManager(getLocalRepoMan(localRepo)); session.setProxySelector(getProxySelector()); session.setMirrorSelector(getMirrorSelector()); session.setAuthenticationSelector(getAuthSelector()); session.setCache(new DefaultRepositoryCache()); session.setRepositoryListener(new AntRepositoryListener(task)); session.setTransferListener(new AntTransferListener(task)); session.setWorkspaceReader(ProjectWorkspaceReader.getInstance()); return session; }
/** Tests that isActive returns false when "unless" references a set property. */ public final void testIsActive5() { ProcessorDef arg = create(); Project project = new Project(); project.setProperty("cond", ""); arg.setProject(project); arg.setUnless("cond"); assertTrue(!arg.isActive()); }
@Override protected String getMessage(String urlString) throws Exception { Project project = getProject(urlString, urlString.substring("file:".length())); GitHubJobMessageUtil.getFailedJobMessage(project); return project.getProperty("report.html.content"); }
/** * Get Property * * @param property name * @return The property value */ public String getProperty(String property) { Project currentProject = getProject(); if (currentProject != null) { return currentProject.getProperty(property); } else { return properties.getProperty(property); } }
/** * get all properties, when project is there got all project Properties * * @return properties */ public Map getProperties() { Project currentProject = getProject(); if (currentProject != null) { return currentProject.getProperties(); } else { return properties; } }
/** * Bind the runner to a project component. Properties, targets and references are all added as * beans; project is bound to project, and self to the component. * * @param component to become <code>self</code> */ public void bindToComponent(ProjectComponent component) { project = component.getProject(); addBeans(project.getProperties()); addBeans(project.getUserProperties()); addBeans(project.getCopyOfTargets()); addBeans(project.getCopyOfReferences()); addBean("project", project); addBean("self", component); }
/** * Signals that a build has started. This event is fired before any targets have started. * * @param event An event with any relevant extra information. Must not be <code>null</code>. */ public void buildStarted(BuildEvent event) { Resource resource = m_context.getResource(); String path = resource.getResourcePath(); String version = resource.getVersion(); Project project = m_context.getProject(); project.log("\n-------------------------------------------------------------------------"); project.log(path + "#" + version); project.log("-------------------------------------------------------------------------"); }
public MonitoredBuild(File buildFile, String target) { myBuildFile = buildFile; this.target = target; project = new Project(); project = new Project(); project.init(); project.setUserProperty("ant.file", myBuildFile.getAbsolutePath()); ProjectHelper.configureProject(project, myBuildFile); }
protected void setUp() throws Exception { createCache(); Project project = new Project(); project.setProperty("ivy.settings.file", "test/repositories/ivysettings-1.xml"); report = new IvyRepositoryReport(); report.setProject(project); System.setProperty("ivy.cache.dir", cache.getAbsolutePath()); }
public boolean shouldRun(Project p) { if (ifProperty != null && p.getProperty(ifProperty) == null) { return false; } else if (unlessProperty != null && p.getProperty(unlessProperty) != null) { return false; } return true; }
/** * Creates a processor initialized to be an extension of the base processor. * * @param baseProcessor base processor * @return extending processor */ protected final ProcessorDef createExtendedProcessorDef(final ProcessorDef baseProcessor) { Project project = new Project(); baseProcessor.setProject(project); baseProcessor.setId("base"); project.addReference("base", baseProcessor); ProcessorDef extendedLinker = create(); extendedLinker.setProject(project); extendedLinker.setExtends(new Reference("base")); return extendedLinker; }
/** tests basic operation of the parallel task */ public void testBasic() { // should get no output at all Project p = getProject(); p.setUserProperty("test.direct", DIRECT_MESSAGE); p.setUserProperty("test.delayed", DELAYED_MESSAGE); expectOutputAndError("testBasic", "", ""); String log = getLog(); assertEquals( "parallel tasks didn't output correct data", log, DIRECT_MESSAGE + DELAYED_MESSAGE); }
private void printHeader(int amount) { String binaryBinaries = amount > 1 ? "Binaries" : "Binary"; project.log(" "); project.log(" "); project.log("======================================================"); project.log(" Testing " + amount + " " + binaryBinaries); project.log("======================================================"); project.log(" "); project.log(" "); }
@Override public void execute() throws BuildException { try { Project project = getProject(); UpgradeTableBuilderInvoker.invoke(project.getBaseDir(), _upgradeTableBuilderArgs); } catch (Exception e) { throw new BuildException(e); } }
public static synchronized AntRepoSys getInstance(Project project) { Object obj = project.getReference(Names.ID); if (obj instanceof AntRepoSys) { return (AntRepoSys) obj; } AntRepoSys instance = new AntRepoSys(project); project.addReference(Names.ID, instance); instance.initDefaults(); return instance; }