use of org.gradle.api.InvalidUserDataException in project gradle by gradle.
the class TaskFactory method create.
@Override
@SuppressWarnings("deprecation")
public <S extends Task> S create(final TaskIdentity<S> identity, @Nullable final Object[] constructorArgs) {
if (!Task.class.isAssignableFrom(identity.type)) {
throw new InvalidUserDataException(String.format("Cannot create task '%s' of type '%s' as it does not implement the Task interface.", identity.identityPath.toString(), identity.type.getSimpleName()));
}
NameValidator.validate(identity.name, "task name", "");
final Class<? extends DefaultTask> implType;
if (identity.type == Task.class) {
implType = DefaultTask.class;
} else if (DefaultTask.class.isAssignableFrom(identity.type)) {
implType = identity.type.asSubclass(DefaultTask.class);
} else if (identity.type == org.gradle.api.internal.AbstractTask.class || identity.type == TaskInternal.class) {
throw new InvalidUserDataException(String.format("Cannot create task '%s' of type '%s' as this type is not supported for task registration.", identity.identityPath.toString(), identity.type.getSimpleName()));
} else {
throw new InvalidUserDataException(String.format("Cannot create task '%s' of type '%s' as directly extending AbstractTask is not supported.", identity.identityPath.toString(), identity.type.getSimpleName()));
}
Describable displayName = Describables.withTypeAndName("task", identity.getIdentityPath());
return org.gradle.api.internal.AbstractTask.injectIntoNewInstance(project, identity, new Callable<S>() {
@Override
public S call() {
try {
Task instance;
if (constructorArgs != null) {
instance = instantiationScheme.instantiator().newInstanceWithDisplayName(implType, displayName, constructorArgs);
} else {
instance = instantiationScheme.deserializationInstantiator().newInstance(implType, org.gradle.api.internal.AbstractTask.class);
}
return identity.type.cast(instance);
} catch (ObjectInstantiationException e) {
throw new TaskInstantiationException(String.format("Could not create task of type '%s'.", identity.type.getSimpleName()), e.getCause());
}
}
});
}
use of org.gradle.api.InvalidUserDataException in project gradle by gradle.
the class DefaultProject method getTasksByName.
@Override
public Set<Task> getTasksByName(final String name, boolean recursive) {
if (isNullOrEmpty(name)) {
throw new InvalidUserDataException("Name is not specified!");
}
final Set<Task> foundTasks = new HashSet<Task>();
Action<Project> action = new Action<Project>() {
@Override
public void execute(Project project) {
// Don't force evaluation of rules here, let the task container do what it needs to
((ProjectInternal) project).getOwner().ensureTasksDiscovered();
Task task = project.getTasks().findByName(name);
if (task != null) {
foundTasks.add(task);
}
}
};
if (recursive) {
allprojects(action);
} else {
action.execute(this);
}
return foundTasks;
}
use of org.gradle.api.InvalidUserDataException in project gradle by gradle.
the class LazyPublishArtifact method getDelegate.
private PublishArtifactInternal getDelegate() {
if (delegate == null) {
Object value = provider.get();
if (value instanceof FileSystemLocation) {
FileSystemLocation location = (FileSystemLocation) value;
delegate = fromFile(location.getAsFile());
} else if (value instanceof File) {
delegate = fromFile((File) value);
} else if (value instanceof AbstractArchiveTask) {
delegate = new ArchivePublishArtifact((AbstractArchiveTask) value);
} else if (value instanceof Task) {
delegate = fromFile(((Task) value).getOutputs().getFiles().getSingleFile());
} else if (fileResolver != null) {
delegate = fromFile(fileResolver.resolve(value));
} else {
throw new InvalidUserDataException(String.format("Cannot convert provided value (%s) to a file.", value));
}
}
return delegate;
}
use of org.gradle.api.InvalidUserDataException in project gradle by gradle.
the class PublishToMavenLocal method computeNormalizedPublication.
private MavenNormalizedPublication computeNormalizedPublication() {
MavenPublicationInternal publicationInternal = getPublicationInternal();
if (publicationInternal == null) {
throw new InvalidUserDataException("The 'publication' property is required");
}
getDuplicatePublicationTracker().checkCanPublishToMavenLocal(publicationInternal);
return publicationInternal.asNormalisedPublication();
}
use of org.gradle.api.InvalidUserDataException in project gradle by gradle.
the class Signature method generate.
/**
* Generates the signature file.
*
* <p>In order to generate the signature, the {@link #getToSign() file to sign}, {@link #getSignatory() signatory} and {@link #getSignatureType() signature type} must be known (i.e. non {@code
* null}).</p>
*
* @throws InvalidUserDataException if the there is insufficient information available to generate the signature.
*/
public void generate() {
File toSign = getToSign();
if (toSign == null) {
if (signatureSpec.isRequired()) {
throw new InvalidUserDataException("Unable to generate signature as the file to sign has not been specified");
} else {
return;
}
}
Signatory signatory = getSignatory();
if (signatory == null) {
if (signatureSpec.isRequired()) {
throw new InvalidUserDataException("Unable to generate signature for \'" + toSign + "\' as no signatory is available to sign");
} else {
return;
}
}
SignatureType signatureType = getSignatureType();
if (signatureType == null) {
if (signatureSpec.isRequired()) {
throw new InvalidUserDataException("Unable to generate signature for \'" + toSign + "\' as no signature type has been configured");
} else {
return;
}
}
signatureType.sign(signatory, toSign);
}
Aggregations