use of org.gradle.api.GradleException in project gradle by gradle.
the class SingleIncludePatternFileTree method doVisit.
private void doVisit(FileVisitor visitor, File file, LinkedList<String> relativePath, int segmentIndex, AtomicBoolean stopFlag) {
if (stopFlag.get()) {
return;
}
String segment = patternSegments.get(segmentIndex);
if (segment.contains("**")) {
PatternSet patternSet = new PatternSet();
patternSet.include(includePattern);
patternSet.exclude(excludeSpec);
DirectoryFileTree fileTree = new DirectoryFileTree(baseDir, patternSet, fileSystem);
fileTree.visitFrom(visitor, file, new RelativePath(file.isFile(), relativePath.toArray(new String[relativePath.size()])));
} else if (segment.contains("*") || segment.contains("?")) {
PatternStep step = PatternStepFactory.getStep(segment, false);
File[] children = file.listFiles();
if (children == null) {
if (!file.canRead()) {
throw new GradleException(String.format("Could not list contents of directory '%s' as it is not readable.", file));
}
// else, might be a link which points to nothing, or has been removed while we're visiting, or ...
throw new GradleException(String.format("Could not list contents of '%s'.", file));
}
for (File child : children) {
if (stopFlag.get()) {
break;
}
String childName = child.getName();
if (step.matches(childName)) {
relativePath.addLast(childName);
doVisitDirOrFile(visitor, child, relativePath, segmentIndex + 1, stopFlag);
relativePath.removeLast();
}
}
} else {
relativePath.addLast(segment);
doVisitDirOrFile(visitor, new File(file, segment), relativePath, segmentIndex + 1, stopFlag);
relativePath.removeLast();
}
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class DefaultTaskClassInfoStore method createTaskClassInfo.
private TaskClassInfo createTaskClassInfo(Class<? extends Task> type) {
boolean cacheable = type.isAnnotationPresent(CacheableTask.class);
boolean incremental = false;
Map<String, Class<?>> processedMethods = Maps.newHashMap();
ImmutableList.Builder<TaskActionFactory> taskActionFactoriesBuilder = ImmutableList.builder();
for (Class current = type; current != null; current = current.getSuperclass()) {
for (Method method : current.getDeclaredMethods()) {
TaskActionFactory taskActionFactory = createTaskAction(type, method, processedMethods);
if (taskActionFactory == null) {
continue;
}
if (taskActionFactory instanceof IncrementalTaskActionFactory) {
if (incremental) {
throw new GradleException(String.format("Cannot have multiple @TaskAction methods accepting an %s parameter.", IncrementalTaskInputs.class.getSimpleName()));
}
incremental = true;
}
taskActionFactoriesBuilder.add(taskActionFactory);
}
}
return new TaskClassInfo(incremental, taskActionFactoriesBuilder.build(), cacheable);
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class TarTaskOutputPacker method pack.
private long pack(Collection<ResolvedTaskOutputFilePropertySpec> propertySpecs, Map<String, Map<String, FileContentSnapshot>> outputSnapshots, TarArchiveOutputStream tarOutput) {
long entries = 0;
for (ResolvedTaskOutputFilePropertySpec propertySpec : propertySpecs) {
String propertyName = propertySpec.getPropertyName();
Map<String, FileContentSnapshot> outputs = outputSnapshots.get(propertyName);
try {
entries += packProperty(propertySpec, outputs, tarOutput);
} catch (Exception ex) {
throw new GradleException(String.format("Could not pack property '%s': %s", propertyName, ex.getMessage()), ex);
}
}
return entries;
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class Wrapper method writeWrapperTo.
private void writeWrapperTo(File destination) {
InputStream gradleWrapperJar = Wrapper.class.getResourceAsStream("/gradle-wrapper.jar");
if (gradleWrapperJar == null) {
throw new GradleException("Cannot locate wrapper JAR resource.");
}
ZipInputStream zipInputStream = null;
ZipOutputStream zipOutputStream = null;
try {
zipInputStream = new ZipInputStream(gradleWrapperJar);
zipOutputStream = new ZipOutputStream(new FileOutputStream(destination));
for (ZipEntry entry = zipInputStream.getNextEntry(); entry != null; entry = zipInputStream.getNextEntry()) {
zipOutputStream.putNextEntry(entry);
if (!entry.isDirectory()) {
ByteStreams.copy(zipInputStream, zipOutputStream);
}
zipOutputStream.closeEntry();
}
addBuildReceipt(zipOutputStream);
} catch (IOException e) {
throw UncheckedException.throwAsUncheckedException(e);
} finally {
IoActions.closeQuietly(zipInputStream);
IoActions.closeQuietly(zipOutputStream);
}
}
use of org.gradle.api.GradleException in project gradle by gradle.
the class BuildScriptBuilder method create.
public TemplateOperation create() {
return new TemplateOperation() {
@Override
public void generate() {
File target = getTargetFile();
try {
PrintWriter writer = new PrintWriter(new FileWriter(target));
try {
PrettyPrinter printer = prettyPrinterFor(dsl, writer);
printer.printFileHeader(headerLines);
printer.printPlugins(plugins);
printer.printConfigSpecs(configSpecs);
if (!dependencies.isEmpty()) {
printer.printDependencies(dependencies);
printer.printRepositories();
}
} finally {
writer.close();
}
} catch (Exception e) {
throw new GradleException("Could not generate file " + target + ".", e);
}
}
};
}
Aggregations