/** * Returns a facade which is associated with the supplied ant project. * * @param component The ant project component used to access the facade. Not <code>null</code>. * * @return A new facade. Not <code>null</code>. */ private static final SvnFacade getFacade( ProjectComponent component ) { // in general I would prefer to use the key by it's own but the code might // become invalid if the ant svn tasks are used in parallel for the same // project (which is unlikely to happen), so here we're providing the necessary // distinction. if( component instanceof SvnCommand ) { // if a command is passed we're using the task for reference component = ((SvnCommand) component).getTask(); } String key = KEY_FACADE + component.hashCode(); SvnFacade result = (SvnFacade) component.getProject().getReference( key ); if( result == null ) { result = new SvnFacade(); component.getProject().addReference( key, result ); } return result; }
private static final SvnSetting getRefidSetting( ProjectComponent component ) { SvnFacade facade = getFacade( component ); if( facade.refidsetting == null ) { if( facade.refid != null ) { Object obj = facade.refid.getReferencedObject( component.getProject() ); if( obj == null ) { throw new BuildException( "The refid attribute value '" + facade.refid + "' doesn't refer to any object." ); } if( !(obj instanceof SvnSetting) ) { throw new BuildException( "The refid attribute value '" + facade.refid + "' has an unknown type [" + obj.getClass().getName() + "]." ); } facade.refidsetting = (SvnSetting) obj; } else { facade.refidsetting = facade.setting; } } return facade.refidsetting; }
protected Properties getDefaultProperties(ProjectComponent task) { URL url = IvySettings.getDefaultPropertiesURL(); // this is copy of loadURL code from ant Property task (not available in 1.5.1) Properties props = new Properties(); task.log("Loading " + url, Project.MSG_VERBOSE); try { InputStream is = url.openStream(); try { props.load(is); } finally { if (is != null) { is.close(); } } } catch (IOException ex) { throw new BuildException(ex); } return props; }
/** {@inheritDoc} */ @Override protected boolean run(Commandline cmd, ProjectComponent log) throws BuildException { ExecuteJava ej = new ExecuteJava(); Class<?> c = getN2aClass(); if (c == null) { throw new BuildException( "Couldn't load Kaffe's Native2Ascii class"); } cmd.setExecutable(c.getName()); ej.setJavaCommand(cmd); ej.execute(log.getProject()); // otherwise ExecuteJava has thrown an exception return true; }
/** * Creates the Native2AsciiAdapter based on the user choice and * potentially the VM vendor. * * @param choice the user choice (if any). * @param log a ProjectComponent instance used to access Ant's * logging system. * @param classpath the classpath to use when looking up an * adapter class * @return The adapter to use. * @throws BuildException if there was a problem. * @since Ant 1.8.0 */ public static Native2AsciiAdapter getAdapter(String choice, ProjectComponent log, Path classpath) throws BuildException { if ((shouldUseKaffee() && choice == null) || KaffeNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) { return new KaffeNative2Ascii(); } else if (SunNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) { return new SunNative2Ascii(); } else if (BuiltinNative2Ascii.IMPLEMENTATION_NAME.equals(choice)) { return new BuiltinNative2Ascii(); } else if (choice != null) { return resolveClassName(choice, // Memory leak in line below log.getProject() .createClassLoader(classpath)); } return new BuiltinNative2Ascii(); }
/** * Returns the <code>ConflictResolution</code> specification used to handle conflicts. * * @param component The ant project component used to access the facade. Not <code>null</code>. * * @return The <code>ConflictResolution</code> specification used to handle conflicts. */ private static final ConflictResolution getConflictResolution( ProjectComponent component ) { ConflictResolution result = getSetting( component ).getConflictResolution(); if( result == null ) { result = getRefidSetting( component ).getConflictResolution(); } return result; }
/** * @see SvnSetting#getUsername() * * @param component The ant project component used to access the facade. Not <code>null</code>. */ private static final String getUsername( ProjectComponent component ) { String result = getSetting( component ).getUsername(); if( result == null ) { result = getRefidSetting( component ).getUsername(); } return result; }
/** * @see SvnSetting#getPassword() * * @param component The ant project component used to access the facade. Not <code>null</code>. */ private static final String getPassword( ProjectComponent component ) { String result = getSetting( component ).getPassword(); if( result == null ) { result = getRefidSetting( component ).getPassword(); } return result; }
/** * @see SvnSetting#getSSLPassword() * * @param component The ant project component used to access the facade. Not <code>null</code>. */ private static final String getSSLPassword( ProjectComponent component ) { String result = getSetting( component ).getSSLPassword(); if( result == null ) { result = getRefidSetting( component ).getSSLPassword(); } return result; }
/** * @see SvnSetting#getSSLClientCertPath() * * @param component The ant project component used to access the facade. Not <code>null</code>. */ private static final File getSSLClientCertPath( ProjectComponent component ) { File result = getSetting( component ).getSSLClientCertPath(); if( result == null ) { result = getRefidSetting( component ).getSSLClientCertPath(); } return result; }
/** * @see SvnSetting#getSSHPort() * * @param component The ant project component used to access the facade. Not <code>null</code>. */ private static final Integer getSSHPort( ProjectComponent component ) { Integer result = getSetting( component ).getSSHPort(); if( result == null ) { result = getRefidSetting( component ).getSSHPort(); } return result; }
/** * @see SvnSetting#getSSHPassphrase() * * @param component The ant project component used to access the facade. Not <code>null</code>. */ private static final String getSSHPassphrase( ProjectComponent component ) { String result = getSetting( component ).getSSHPassphrase(); if( result == null ) { result = getRefidSetting( component ).getSSHPassphrase(); } return result; }
/** * @see SvnSetting#getSSHKeyPath() * * @param component The ant project component used to access the facade. Not <code>null</code>. */ private static final File getSSHKeyPath( ProjectComponent component ) { File result = getSetting( component ).getSSHKeyPath(); if( result == null ) { result = getRefidSetting( component ).getSSHKeyPath(); } return result; }
/** * @see SvnSetting#getConfigDirectory() */ private static final File getConfigDirectory( ProjectComponent component ) { File result = getSetting( component ).getConfigDirectory(); if( result == null ) { result = getRefidSetting( component ).getConfigDirectory(); } return result; }
/** * @see SvnSetting#getCertReject() * * @param component The ant project component used to access the facade. Not <code>null</code>. */ private static final Boolean getCertReject( ProjectComponent component ) { Boolean result = getSetting( component ).getCertReject(); if( result == null ) { result = getRefidSetting( component ).getCertReject(); } return result; }
/** * @see SvnSetting#getDateFormatter() * * @param component The ant project component used to access the facade. Not <code>null</code>. */ public static final String getDateFormatter( ProjectComponent component ) { String result = getSetting( component ).getDateFormatter(); if( (result == null) || (result.length() == 0) ) { result = getRefidSetting( component ).getDateFormatter(); } if( (result == null) || (result.length() == 0) ) { result = DEFAULT_DATEFORMATTER; } return result; }
/** * @see SvnSetting#getDateTimezone() * * @param component The ant project component used to access the facade. Not <code>null</code>. */ public static final TimeZone getDateTimezone( ProjectComponent component ) { String zone = getSetting( component ).getDateTimezone(); if( (zone == null) || (zone.length() == 0) ) { zone = getRefidSetting( component ).getDateTimezone(); } if( (zone == null) || (zone.length() == 0) ) { return null; } else { return TimeZone.getTimeZone( zone ); } }
/** * Returns <code>true</code> if a failure shall abort the build process. * * @param component The ant project component used to access the facade. * Not <code>null</code>. * * @return <code>true</code> <=> A failure has to abort the build process. */ public static final boolean getFailonerror( ProjectComponent component ) { Boolean result = getSetting( component ).getFailonerror(); if( result == null ) { result = getRefidSetting( component ).getFailonerror(); } if( result == null ) { result = DEFAULT_FAILONERROR; } return result.booleanValue(); }
/** * This method returns a SVN client adapter, based on the property set to the svn task. * More specifically, the 'javahl' and 'svnkit' flags are verified, as well as the * availability of JAVAHL ad SVNKit adapters, to decide what flavour to use. * * @param component The ant project component used to access the facade. * Not <code>null</code>. * * @return An instance of SVN client adapter that meets the specified constraints, if any. * Not <code>null</code>. * * @throws BuildException Thrown in a situation where no adapter can fit the constraints. */ public static final synchronized ISVNClientAdapter getClientAdapter( ProjectComponent component ) throws BuildException { SvnClientType clienttype = getClientType( component ); ISVNClientAdapter result = clienttype.createClient(); File configdir = getConfigDirectory( component ); if( configdir != null ) { try { result.setConfigDirectory( configdir ); } catch( SVNClientException ex ) { throw new BuildException( "Failed to change the configuration directory to '" + configdir.getAbsolutePath() + "' !", ex ); } } ConflictResolution conflictresolution = getConflictResolution( component ); if( conflictresolution != null ) { result.addConflictResolutionCallback( new DefaultConflictResolver( conflictresolution ) ); } if( getUsername( component ) != null ) { result.setUsername( getUsername( component ) ); } if( clienttype == SvnClientType.cli ) { if( getPassword( component ) != null ) { result.setPassword( getPassword( component ) ); } } else { result.addPasswordCallback( new DefaultPasswordCallback( getUsername ( component ), getPassword ( component ), getSSHKeyPath ( component ), getSSHPassphrase ( component ), getSSHPort ( component ), getSSLClientCertPath ( component ), getSSLPassword ( component ), getCertReject ( component ) ) ); } return result; }
/** * Returns the default ivy settings of this classloader. If it doesn't exist yet, a new one is * created using the given project to back the VariableContainer. * * @param task * TODO add text. * @return An IvySetting instance. */ public static IvyAntSettings getDefaultInstance(ProjectComponent task) { Project project = task.getProject(); Object defaultInstanceObj = project.getReference("ivy.instance"); if (defaultInstanceObj != null && defaultInstanceObj.getClass().getClassLoader() != IvyAntSettings.class .getClassLoader()) { task.log("ivy.instance reference an ivy:settings defined in an other classloader. " + "An new default one will be used in this project.", Project.MSG_WARN); defaultInstanceObj = null; } if (defaultInstanceObj != null && !(defaultInstanceObj instanceof IvyAntSettings)) { throw new BuildException("ivy.instance reference a " + defaultInstanceObj.getClass().getName() + " an not an IvyAntSettings. Please don't use this reference id ()"); } if (defaultInstanceObj == null) { task.log("No ivy:settings found for the default reference 'ivy.instance'. " + "A default instance will be used", Project.MSG_VERBOSE); IvyAntSettings settings = new IvyAntSettings(); settings.setProject(project); project.addReference("ivy.instance", settings); settings.createIvyEngine(task); return settings; } else { return (IvyAntSettings) defaultInstanceObj; } }
/** * Return the configured Ivy instance. * * @param task ProjectComponent * @return Returns the configured Ivy instance. */ public Ivy getConfiguredIvyInstance(ProjectComponent task) { if (ivyEngine == null) { createIvyEngine(task); } return ivyEngine; }
/** * Creates the JavahAdapter based on the user choice and * potentially the VM vendor. * * @param choice the user choice (if any). * @param log a ProjectComponent instance used to access Ant's * logging system. * @param classpath the classpath to use when looking up an * adapter class * @return The adapter to use. * @throws BuildException if there is an error. * @since Ant 1.8.0 */ public static JavahAdapter getAdapter(String choice, ProjectComponent log, Path classpath) throws BuildException { if ((JavaEnvUtils.isKaffe() && choice == null) || Kaffeh.IMPLEMENTATION_NAME.equals(choice)) { return new Kaffeh(); } if ((JavaEnvUtils.isGij() && choice == null) || Gcjh.IMPLEMENTATION_NAME.equals(choice)) { return new Gcjh(); } if (JavaEnvUtils.isAtLeastJavaVersion("10") && (choice == null || ForkingJavah.IMPLEMENTATION_NAME.equals(choice))) { throw new BuildException("javah does not exist under Java 10 and higher," + " use the javac task with nativeHeaderDir instead"); } if (ForkingJavah.IMPLEMENTATION_NAME.equals(choice)) { return new ForkingJavah(); } if (SunJavah.IMPLEMENTATION_NAME.equals(choice)) { return new SunJavah(); } if (choice != null) { return resolveClassName(choice, // Memory leak in line below log.getProject() .createClassLoader(classpath)); } return new ForkingJavah(); }
/** * Run the Java command in a separate VM, this does not give you * the full flexibility of the Java task, but may be enough for * simple needs. * @param pc the ProjectComponent to use for logging, etc. * @return the exit status of the subprocess. * @throws BuildException on error. * @since Ant 1.6.3 */ public int fork(ProjectComponent pc) throws BuildException { CommandlineJava cmdl = new CommandlineJava(); cmdl.setClassname(javaCommand.getExecutable()); String[] args = javaCommand.getArguments(); for (int i = 0; i < args.length; i++) { cmdl.createArgument().setValue(args[i]); } if (classpath != null) { cmdl.createClasspath(pc.getProject()).append(classpath); } if (sysProperties != null) { cmdl.addSysproperties(sysProperties); } Redirector redirector = new Redirector(pc); Execute exe = new Execute(redirector.createHandler(), timeout == null ? null : new ExecuteWatchdog(timeout.longValue())); exe.setAntRun(pc.getProject()); if (Os.isFamily("openvms")) { setupCommandLineForVMS(exe, cmdl.getCommandline()); } else { exe.setCommandline(cmdl.getCommandline()); } try { int rc = exe.execute(); redirector.complete(); return rc; } catch (IOException e) { throw new BuildException(e); } finally { timedOut = exe.killedProcess(); } }
/** * Tells which sources should be reprocessed because the given * selector selects at least one target. * * @param logTo where to send (more or less) interesting output. * @param source ResourceCollection. * @param mapper filename mapper indicating how to find the target Resources. * @param targets object able to map a relative path as a Resource. * @param selector returns a selector that is applied to target * files. If it selects at least one target the source will be * added to the returned collection. * @return ResourceCollection. * @since Ant 1.8.0 */ public static ResourceCollection selectSources(final ProjectComponent logTo, ResourceCollection source, final FileNameMapper mapper, final ResourceFactory targets, final ResourceSelectorProvider selector) { if (source.isEmpty()) { logTo.log("No sources found.", Project.MSG_VERBOSE); return Resources.NONE; } source = Union.getInstance(source); final Union result = new Union(); for (final Resource sr : source) { String srName = sr.getName(); srName = srName == null ? srName : srName.replace('/', File.separatorChar); String[] targetnames = null; try { targetnames = mapper.mapFileName(srName); } catch (final Exception e) { logTo.log("Caught " + e + " mapping resource " + sr, Project.MSG_VERBOSE); } if (targetnames == null || targetnames.length == 0) { logTo.log(sr + " skipped - don\'t know how to handle it", Project.MSG_VERBOSE); continue; } for (int i = 0; i < targetnames.length; i++) { if (targetnames[i] == null) { targetnames[i] = "(no name)"; } } final Union targetColl = new Union(); for (int i = 0; i < targetnames.length; i++) { targetColl.add(targets.getResource( targetnames[i].replace(File.separatorChar, '/'))); } //find the out-of-date targets: final Restrict r = new Restrict(); r.add(selector.getTargetSelectorForSource(sr)); r.add(targetColl); if (r.size() > 0) { result.add(sr); final Resource t = r.iterator().next(); logTo.log(sr.getName() + " added as " + t.getName() + (t.isExists() ? " is outdated." : " doesn\'t exist."), Project.MSG_VERBOSE); continue; } //log uptodateness of all targets: logTo.log(sr.getName() + " omitted as " + targetColl.toString() + (targetColl.size() == 1 ? " is" : " are ") + " up to date.", Project.MSG_VERBOSE); } return result; }
/** * Log which Resources (if any) have been modified in the future. * @param logTo the ProjectComponent to do the logging. * @param rc the collection of Resources to check. * @param granularity the timestamp granularity to use. * @since Ant 1.7 */ private static void logFuture(final ProjectComponent logTo, final ResourceCollection rc, final long granularity) { final long now = System.currentTimeMillis() + granularity; final Date sel = new Date(); sel.setMillis(now); sel.setWhen(TimeComparison.AFTER); final Restrict future = new Restrict(); future.add(sel); future.add(rc); for (final Resource r : future) { logTo.log("Warning: " + r.getName() + " modified in the future.", Project.MSG_WARN); } }
/** * 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); }
/** * {@inheritDoc} */ public ProjectComponent getProjectComponent() { return this; }
private static final SvnClientType getClientType( ProjectComponent component ) { return getRefidSetting( component ).getClient(); }
private <T extends ProjectComponent & ResourceCollection> T addSignaturesResource(T res) { res.setProject(getProject()); apiSignatures.add(res); return res; }
public static IvyAntSettings getDefaultInstance(Task task) { return getDefaultInstance((ProjectComponent) task); }
public Ivy getConfiguredIvyInstance(Task task) { return getConfiguredIvyInstance((ProjectComponent) task); }
void createIvyEngine(final ProjectComponent task) { Project project = task.getProject(); Property prop = new Property() { public void execute() throws BuildException { addProperties(getDefaultProperties(task)); } }; prop.setProject(project); prop.init(); prop.execute(); IvyAntVariableContainer ivyAntVariableContainer = new IvyAntVariableContainer(project); IvySettings settings = new IvySettings(ivyAntVariableContainer); settings.setBaseDir(project.getBaseDir()); if (file == null && url == null) { defineDefaultSettingFile(ivyAntVariableContainer, task); } if (antWorkspaceResolver != null) { settings.addConfigured(antWorkspaceResolver.getResolver()); } Ivy ivy = Ivy.newInstance(settings); try { ivy.pushContext(); AntMessageLogger.register(task, ivy); Message.showInfo(); configureURLHandler(); if (file != null) { if (!file.exists()) { throw new BuildException("settings file does not exist: " + file); } ivy.configure(file); } else { if (url == null) { throw new AssertionError( "ivy setting should have either a file, either an url," + " and if not defineDefaultSettingFile must set it."); } ivy.configure(url); } ivyAntVariableContainer.updateProject(id); ivyEngine = ivy; } catch (ParseException | IOException e) { throw new BuildException("impossible to configure ivy:settings with given " + (file != null ? "file: " + file : "url: " + url) + " : " + e, e); } finally { ivy.popContext(); } }
/** * Set file or url to its default value * * @param variableContainer IvyVariableContainer */ private void defineDefaultSettingFile(IvyVariableContainer variableContainer, ProjectComponent task) { String settingsFileName = variableContainer.getVariable("ivy.conf.file"); if (settingsFileName != null && !settingsFileName.equals(variableContainer.getVariable("ivy.settings.file"))) { task.log("DEPRECATED: 'ivy.conf.file' is deprecated, use 'ivy.settings.file' instead", Project.MSG_INFO); } else { settingsFileName = variableContainer.getVariable("ivy.settings.file"); } File[] settingsLocations = new File[] { new File(getProject().getBaseDir(), settingsFileName), new File(getProject().getBaseDir(), "ivyconf.xml"), new File(settingsFileName), new File("ivyconf.xml")}; for (File settingsFile : settingsLocations) { task.log("searching settings file: trying " + settingsFile, Project.MSG_VERBOSE); if (settingsFile.exists()) { file = settingsFile; break; } } if (file == null) { if (Boolean.valueOf(getProject().getProperty("ivy.14.compatible"))) { task.log("no settings file found, using Ivy 1.4 default...", Project.MSG_VERBOSE); url = IvySettings.getDefault14SettingsURL(); } else { String settingsFileUrl = variableContainer.getVariable("ivy.settings.url"); if (settingsFileUrl != null) { try { url = new URL(settingsFileUrl); } catch (MalformedURLException e) { throw new BuildException( "Impossible to configure ivy:settings with given url: " + settingsFileUrl + ": " + e.getMessage(), e); } } else { task.log("no settings file found, using default...", Project.MSG_VERBOSE); url = IvySettings.getDefaultSettingsURL(); } } } }
/** * Create a new LogOutputResource. * @param managingComponent ditto */ public LogOutputResource(ProjectComponent managingComponent) { super(NAME); outputStream = new LogOutputStream(managingComponent); }
@Override public void initialize(@Nonnull AnalysisContext analysisContext) { this.logger = (ProjectComponent) analysisContext.getData(ANT_REPORTER_LOGGER_KEY); this.minSeverity = (DifferenceSeverity) analysisContext.getData(MIN_SEVERITY_KEY); }
/** * Tells which source files should be reprocessed based on the * last modification date of target files. * @param logTo where to send (more or less) interesting output. * @param source array of resources bearing relative path and last * modification date. * @param mapper filename mapper indicating how to find the target * files. * @param targets object able to map as a resource a relative path * at <b>destination</b>. * @return array containing the source files which need to be * copied or processed, because the targets are out of date or do * not exist. */ public static Resource[] selectOutOfDateSources(final ProjectComponent logTo, final Resource[] source, final FileNameMapper mapper, final ResourceFactory targets) { return selectOutOfDateSources(logTo, source, mapper, targets, FILE_UTILS.getFileTimestampGranularity()); }
/** * Tells which source files should be reprocessed based on the * last modification date of target files. * @param logTo where to send (more or less) interesting output. * @param source array of resources bearing relative path and last * modification date. * @param mapper filename mapper indicating how to find the target * files. * @param targets object able to map as a resource a relative path * at <b>destination</b>. * @param granularity The number of milliseconds leeway to give * before deciding a target is out of date. * @return array containing the source files which need to be * copied or processed, because the targets are out of date or do * not exist. * @since Ant 1.6.2 */ public static Resource[] selectOutOfDateSources(final ProjectComponent logTo, final Resource[] source, final FileNameMapper mapper, final ResourceFactory targets, final long granularity) { final Union u = new Union(); u.addAll(Arrays.asList(source)); final ResourceCollection rc = selectOutOfDateSources(logTo, u, mapper, targets, granularity); return rc.size() == 0 ? new Resource[0] : ((Union) rc).listResources(); }
/** * Tells which sources should be reprocessed based on the * last modification date of targets. * @param logTo where to send (more or less) interesting output. * @param source ResourceCollection. * @param mapper filename mapper indicating how to find the target Resources. * @param targets object able to map a relative path as a Resource. * @param granularity The number of milliseconds leeway to give * before deciding a target is out of date. * @return ResourceCollection. * @since Ant 1.7 */ public static ResourceCollection selectOutOfDateSources(final ProjectComponent logTo, final ResourceCollection source, final FileNameMapper mapper, final ResourceFactory targets, final long granularity) { logFuture(logTo, source, granularity); return selectSources(logTo, source, mapper, targets, sr -> target -> SelectorUtils.isOutOfDate(sr, target, granularity)); }
/** * Bind the runner to a project component. * The project and self are the only beans set. * @param component to become <code>self</code> */ public void bindToComponentMinimum(ProjectComponent component) { project = component.getProject(); addBean("project", project); addBean("self", component); }
/** * Returns the settings used by this facade. * * @param component The ant project component used to access the facade. Not <code>null</code>. * * @return The settings used by this facade. Not <code>null</code>. */ private static final SvnSetting getSetting( ProjectComponent component ) { return getFacade( component ).setting; }