package org.jboss.shrinkwrap.resolver.impl.maven.task;
import java.io.File;
import org.jboss.shrinkwrap.resolver.api.InvalidConfigurationFileException;
import org.jboss.shrinkwrap.resolver.api.maven.MavenWorkingSession;
import org.jboss.shrinkwrap.resolver.impl.maven.util.Validate;
public class ConfigureSettingsFromFileTask implements MavenWorkingSessionTask<MavenWorkingSession> {
private final File settingsXmlFile;
public ConfigureSettingsFromFileTask(final File settingsXmlFile) throws InvalidConfigurationFileException {
assert settingsXmlFile != null;
assert settingsXmlFile.exists();
this.settingsXmlFile = settingsXmlFile;
}
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");
}
catch (IllegalArgumentException e) {
throw new InvalidConfigurationFileException(e.getMessage());
}
this.settingsXmlFile = new File(resolvedPath);
}
@Override
public MavenWorkingSession execute(final MavenWorkingSession session) {
try {
Validate.isReadable(settingsXmlFile, "Path to the settings.xml ('" + settingsXmlFile
+ "') must be defined and accessible");
}
catch (IllegalArgumentException e) {
throw new InvalidConfigurationFileException(e.getMessage());
}
return session.configureSettingsFromFile(null, settingsXmlFile);
}
}