public ConfigureSettingsFromFileTask(final String pathToSettingsXmlFile) throws InvalidConfigurationFileException { assert pathToSettingsXmlFile != null && pathToSettingsXmlFile.length() > 0; String resolvedPath = null; try { resolvedPath = pathToSettingsXmlFile; Validate.isReadable(resolvedPath, "Path to the settings.xml ('" + pathToSettingsXmlFile + "') must be defined and accessible"); } // rewrap exception catch (IllegalArgumentException e) { throw new InvalidConfigurationFileException(e.getMessage()); } this.settingsXmlFile = new File(resolvedPath); }
/** * Checks that the specified String is not null or empty and represents a readable file, throws exception if it is * empty or null and does not represent a path to a file. * * @param path * The path to check * @param message * The exception message * @throws IllegalArgumentException * Thrown if path is empty, null or invalid */ public static void isReadable(final String path, String message) throws IllegalArgumentException { notNullOrEmpty(path, message); isReadable(new File(path), message); } }
public ConfigureSettingsFromFileTask(final String pathToSettingsXmlFile) throws InvalidConfigurationFileException { assert pathToSettingsXmlFile != null && pathToSettingsXmlFile.length() > 0; String resolvedPath = null; try { resolvedPath = pathToSettingsXmlFile; Validate.isReadable(resolvedPath, "Path to the settings.xml ('" + pathToSettingsXmlFile + "') must be defined and accessible"); } // rewrap exception catch (IllegalArgumentException e) { throw new InvalidConfigurationFileException(e.getMessage()); } this.settingsXmlFile = new File(resolvedPath); }
/** * Checks that the specified String is not null or empty and represents a readable file, throws exception if it is * empty or null and does not represent a path to a file. * * @param path * The path to check * @param message * The exception message * @throws IllegalArgumentException * Thrown if path is empty, null or invalid */ public static void isReadable(final String path, String message) throws IllegalArgumentException { notNullOrEmpty(path, message); isReadable(new File(path), message); } }
/** * Checks that the specified String is not null or empty and represents a readable file, throws exception if it is * empty or null and does not represent a path to a file. * * @param path * The path to check * @param message * The exception message * @throws IllegalArgumentException * Thrown if path is empty, null or invalid */ public static void readable(final File path, final String message) throws IllegalArgumentException { notNull(path, message); if (!isReadable(path)) { throw new IllegalArgumentException(message); } }
/** * Checks that the specified String is not null or empty and represents a readable file, throws exception if it is * empty or null and does not represent a path to a file. * * @param path * The path to check * @param message * The exception message * @throws IllegalArgumentException * Thrown if path is empty, null or invalid */ public static void readable(final File path, final String message) throws IllegalArgumentException { notNull(path, message); if (!isReadable(path)) { throw new IllegalArgumentException(message); } }
@Override public MavenWorkingSession execute(final MavenWorkingSession session) { try { Validate.isReadable(settingsXmlFile, "Path to the settings.xml ('" + settingsXmlFile + "') must be defined and accessible"); } // rewrap exception catch (IllegalArgumentException e) { throw new InvalidConfigurationFileException(e.getMessage()); } return session.configureSettingsFromFile(null, settingsXmlFile); }
@Override public MavenWorkingSession execute(final MavenWorkingSession session) { try { Validate.isReadable(settingsXmlFile, "Path to the settings.xml ('" + settingsXmlFile + "') must be defined and accessible"); } // rewrap exception catch (IllegalArgumentException e) { throw new InvalidConfigurationFileException(e.getMessage()); } return session.configureSettingsFromFile(null, settingsXmlFile); }
MavenSecurityDispatcher(File securitySettings) throws InvalidConfigurationFileException { this.cipher = new MavenPlexusCipher(); this.securitySettingsPath = securitySettings; // settings-security is loaded only if it exists // error is raised later only in case that it is missing but needed if (Validate.isReadable(securitySettings.getAbsoluteFile())) { try { this.securitySettings = SecUtil.read(securitySettings.getAbsolutePath(), true); } catch (SecDispatcherException e) { // exception is ignored, just logged to end user so he's aware of the problem // this is default Maven behavior log.log(Level.WARNING, "Unable to read security configuration from: " + securitySettings.getAbsolutePath() + ". Configuration will be ignored.", e); } } }
MavenSecurityDispatcher(File securitySettings) throws InvalidConfigurationFileException { this.cipher = new MavenPlexusCipher(); this.securitySettingsPath = securitySettings; // settings-security is loaded only if it exists // error is raised later only in case that it is missing but needed if (Validate.isReadable(securitySettings.getAbsoluteFile())) { try { this.securitySettings = SecUtil.read(securitySettings.getAbsolutePath(), true); } catch (SecDispatcherException e) { // exception is ignored, just logged to end user so he's aware of the problem // this is default Maven behavior log.log(Level.WARNING, "Unable to read security configuration from: " + securitySettings.getAbsolutePath() + ". Configuration will be ignored.", e); } } }
@Override public List<org.jboss.shrinkwrap.resolver.api.maven.pom.Resource> getResources() { List<org.jboss.shrinkwrap.resolver.api.maven.pom.Resource> list = new ArrayList<org.jboss.shrinkwrap.resolver.api.maven.pom.Resource>(); List<Resource> resources = model.getBuild().getResources(); // FIXME resources content should be filtered for (Resource res : resources) { // we add resources only if they can be read File resourceDir = new File(res.getDirectory()); if (!Validate.isReadable(resourceDir)) { continue; } // add all files including includes and exclude based filtering String targetPrefix = res.getTargetPath(); for (String relPath : FileUtils.listFiles(resourceDir, res.getIncludes(), res.getExcludes())) { list.add(new org.jboss.shrinkwrap.resolver.api.maven.pom.Resource(new File(resourceDir, relPath), normalizeTargetPath(targetPrefix, relPath))); } } return list; }
@Override public List<org.jboss.shrinkwrap.resolver.api.maven.pom.Resource> getResources() { List<org.jboss.shrinkwrap.resolver.api.maven.pom.Resource> list = new ArrayList<org.jboss.shrinkwrap.resolver.api.maven.pom.Resource>(); List<Resource> resources = model.getBuild().getResources(); // FIXME resources content should be filtered for (Resource res : resources) { // we add resources only if they can be read File resourceDir = new File(res.getDirectory()); if (!Validate.isReadable(resourceDir)) { continue; } // add all files including includes and exclude based filtering String targetPrefix = res.getTargetPath(); for (String relPath : FileUtils.listFiles(resourceDir, res.getIncludes(), res.getExcludes())) { list.add(new org.jboss.shrinkwrap.resolver.api.maven.pom.Resource(new File(resourceDir, relPath), normalizeTargetPath(targetPrefix, relPath))); } } return list; }
@Override public List<org.jboss.shrinkwrap.resolver.api.maven.pom.Resource> getTestResources() { List<org.jboss.shrinkwrap.resolver.api.maven.pom.Resource> list = new ArrayList<org.jboss.shrinkwrap.resolver.api.maven.pom.Resource>(); List<Resource> resources = model.getBuild().getTestResources(); // FIXME resources content should be filtered for (Resource res : resources) { // we add resources only if they can be read File resourceDir = new File(res.getDirectory()); if (!Validate.isReadable(resourceDir)) { continue; } // add all files including includes and exclude based filtering String targetPrefix = res.getTargetPath(); for (String relPath : FileUtils.listFiles(resourceDir, res.getIncludes(), res.getExcludes())) { list.add(new org.jboss.shrinkwrap.resolver.api.maven.pom.Resource(new File(resourceDir, relPath), normalizeTargetPath(targetPrefix, relPath))); } } return list; }
@Override public List<org.jboss.shrinkwrap.resolver.api.maven.pom.Resource> getTestResources() { List<org.jboss.shrinkwrap.resolver.api.maven.pom.Resource> list = new ArrayList<org.jboss.shrinkwrap.resolver.api.maven.pom.Resource>(); List<Resource> resources = model.getBuild().getTestResources(); // FIXME resources content should be filtered for (Resource res : resources) { // we add resources only if they can be read File resourceDir = new File(res.getDirectory()); if (!Validate.isReadable(resourceDir)) { continue; } // add all files including includes and exclude based filtering String targetPrefix = res.getTargetPath(); for (String relPath : FileUtils.listFiles(resourceDir, res.getIncludes(), res.getExcludes())) { list.add(new org.jboss.shrinkwrap.resolver.api.maven.pom.Resource(new File(resourceDir, relPath), normalizeTargetPath(targetPrefix, relPath))); } } return list; }
@Override public MavenWorkingSession execute(MavenWorkingSession session) { String pomFile = SecurityActions.getProperty(POM_FILE_KEY); if (Validate.isNullOrEmpty(pomFile)) { throw new InvalidEnvironmentException(CONSTRUCTION_EXCEPTION); } Validate.isReadable(pomFile, "POM file " + pomFile + " does not represent a readable file"); String userSettings = SecurityActions.getProperty(USER_SETTINGS_KEY); if (Validate.isNullOrEmpty(userSettings)) { throw new InvalidEnvironmentException(CONSTRUCTION_EXCEPTION); } boolean hasSettingsXml = true; try { Validate.isReadable(userSettings, "Settings.xml file " + userSettings + " does not represent a readable file"); } catch (final IllegalArgumentException iae) { hasSettingsXml = false; } if (hasSettingsXml) { session = new ConfigureSettingsFromFileTask(userSettings).execute(session); } String activeProfiles = SecurityActions.getProperty(ACTIVE_PROFILES_KEY); String[] profiles = new String[0]; if (!Validate.isNullOrEmpty(activeProfiles)) { profiles = activeProfiles.split(","); } return LoadPomTask.loadPomFromFile(pomFile, profiles).execute(session); }
@Override public MavenWorkingSession execute(MavenWorkingSession session) { String pomFile = SecurityActions.getProperty(POM_FILE_KEY); if (Validate.isNullOrEmpty(pomFile)) { throw new InvalidEnvironmentException(CONSTRUCTION_EXCEPTION); } Validate.isReadable(pomFile, "POM file " + pomFile + " does not represent a readable file"); String userSettings = SecurityActions.getProperty(USER_SETTINGS_KEY); if (Validate.isNullOrEmpty(userSettings)) { throw new InvalidEnvironmentException(CONSTRUCTION_EXCEPTION); } boolean hasSettingsXml = true; try { Validate.isReadable(userSettings, "Settings.xml file " + userSettings + " does not represent a readable file"); } catch (final IllegalArgumentException iae) { hasSettingsXml = false; } if (hasSettingsXml) { session = new ConfigureSettingsFromFileTask(userSettings).execute(session); } String activeProfiles = SecurityActions.getProperty(ACTIVE_PROFILES_KEY); String[] profiles = new String[0]; if (!Validate.isNullOrEmpty(activeProfiles)) { profiles = activeProfiles.split(","); } return LoadPomTask.loadPomFromFile(pomFile, profiles).execute(session); }
if (Validate.isReadable(pomFile.getSourceDirectory())) { compile(pomFile.getSourceDirectory(), pomFile.getBuildOutputDirectory(), ScopeType.COMPILE, ScopeType.IMPORT, ScopeType.PROVIDED, ScopeType.RUNTIME, ScopeType.SYSTEM); if (Validate.isReadable(warConfiguration.getWarSourceDirectory())) { WebArchive webapp = ShrinkWrap.create(ExplodedImporter.class, "webapp.war") .importDirectory(warConfiguration.getWarSourceDirectory(), createFilter(warConfiguration))
if (Validate.isReadable(pomFile.getSourceDirectory())) { compile(pomFile.getSourceDirectory(), pomFile.getBuildOutputDirectory(), ScopeType.COMPILE, ScopeType.IMPORT, ScopeType.PROVIDED, ScopeType.RUNTIME, ScopeType.SYSTEM); if (Validate.isReadable(warConfiguration.getWarSourceDirectory())) { WebArchive webapp = ShrinkWrap.create(ExplodedImporter.class, "webapp.war") .importDirectory(warConfiguration.getWarSourceDirectory(), createFilter(warConfiguration))
@Override public JarPackagingProcessor importBuildOutput(MavenResolutionStrategy strategy) throws ResolutionException, IllegalArgumentException, UnsupportedOperationException { final ParsedPomFile pomFile = session.getParsedPomFile(); // add source filed if any if (Validate.isReadable(pomFile.getSourceDirectory())) { compile(pomFile.getSourceDirectory(), pomFile.getBuildOutputDirectory(), ScopeType.COMPILE, ScopeType.IMPORT, ScopeType.PROVIDED, ScopeType.RUNTIME, ScopeType.SYSTEM); JavaArchive classes = ShrinkWrap.create(ExplodedImporter.class, "sources.jar") .importDirectory(pomFile.getBuildOutputDirectory()).as(JavaArchive.class); archive = archive.merge(classes); } JarPluginConfiguration jarConfiguration = new JarPluginConfiguration(pomFile); // add resources for (Resource resource : pomFile.getResources()) { archive.addAsResource(resource.getSource(), resource.getTargetPath()); } // set manifest Manifest manifest = jarConfiguration.getArchiveConfiguration().asManifest(); archive.setManifest(new ManifestAsset(manifest)); // construct new archive via applying includes/excludes archive = ArchiveFilteringUtils.filterArchiveContent(archive, JavaArchive.class, jarConfiguration.getIncludes(), jarConfiguration.getExcludes()); return this; }
@Override public JarPackagingProcessor importBuildOutput(MavenResolutionStrategy strategy) throws ResolutionException, IllegalArgumentException, UnsupportedOperationException { final ParsedPomFile pomFile = session.getParsedPomFile(); // add source filed if any if (Validate.isReadable(pomFile.getSourceDirectory())) { compile(pomFile.getSourceDirectory(), pomFile.getBuildOutputDirectory(), ScopeType.COMPILE, ScopeType.IMPORT, ScopeType.PROVIDED, ScopeType.RUNTIME, ScopeType.SYSTEM); JavaArchive classes = ShrinkWrap.create(ExplodedImporter.class, "sources.jar") .importDirectory(pomFile.getBuildOutputDirectory()).as(JavaArchive.class); archive = archive.merge(classes); } JarPluginConfiguration jarConfiguration = new JarPluginConfiguration(pomFile); // add resources for (Resource resource : pomFile.getResources()) { archive.addAsResource(resource.getSource(), resource.getTargetPath()); } // set manifest Manifest manifest = jarConfiguration.getArchiveConfiguration().asManifest(); archive.setManifest(new ManifestAsset(manifest)); // construct new archive via applying includes/excludes archive = ArchiveFilteringUtils.filterArchiveContent(archive, JavaArchive.class, jarConfiguration.getIncludes(), jarConfiguration.getExcludes()); return this; }