public <T extends Task> T findSingleTaskWithType(Class<T> type) { DomainObjectSet<T> tasks = withType(type); if (tasks.size() == 0) { return null; } if (tasks.size() > 1) { throw new UnknownDomainObjectException(String.format("Multiple tasks with type '%s' found.", type.getSimpleName())); } return tasks.iterator().next(); }
public T getByName(String name) throws UnknownDomainObjectException { T t = findByName(name); if (t == null) { throw createNotFoundException(name); } return t; }
public <T> T findByType(Class<T> type) { ExtensionHolder<T> holder; try { holder = getHolderByType(type); } catch (UnknownDomainObjectException e) { return null; } return holder.get(); }
private <T> ExtensionHolder<T> getHolderByType(Class<T> type) { List<String> types = new LinkedList<String>(); for (ExtensionHolder extensionHolder : extensions.values()) { Class<?> clazz = extensionHolder.getType(); types.add(clazz.getSimpleName()); if (type.isAssignableFrom(clazz)) { return extensionHolder; } } throw new UnknownDomainObjectException("Extension of type '" + type.getSimpleName() + "' does not exist. Currently registered extension types: " + types); }
protected <T extends Task> T findSingleTaskWithType(Class<T> type) { DomainObjectSet<T> tasks = withType(type); if (tasks.size() == 0) { return null; } if (tasks.size() > 1) { throw new UnknownDomainObjectException(String.format("Multiple tasks with type '%s' found.", type.getSimpleName())); } return tasks.iterator().next(); }
private <T extends Task> T findOnlyWithType(Class<T> type) { DomainObjectSet<T> tasks = withType(type); if (tasks.size() == 0) { return null; } if (tasks.size() > 1) { throw new UnknownDomainObjectException(String.format("Multiple task with type '%s' found", type.getSimpleName())); } return tasks.iterator().next(); }
public ModsIOExtension(Project project) { this.project = project; if (minecraft == null) { try { minecraft = (String) project.getExtensions().getByName("minecraft").getClass().getField("version").get(project.getExtensions().getByName("minecraft")); if (minecraft.indexOf('-') != 0) { minecraft = minecraft.substring(0, minecraft.indexOf('-')); } } catch (UnknownDomainObjectException ignored) { } catch (Throwable e) { e.printStackTrace(); } } }
public String getMinecraft() { if (minecraft == null) { try { minecraft = (String) project.getExtensions().getByName("minecraft").getClass().getField("version").get(project.getExtensions().getByName("minecraft")); if (minecraft.indexOf('-') != 0) { minecraft = minecraft.substring(0, minecraft.indexOf('-')); } } catch (UnknownDomainObjectException ignored) { } catch (Throwable e) { e.printStackTrace(); } } return minecraft; }
@Override protected UnknownDomainObjectException createNotFoundException(String name) { return new UnknownConfigurationException(String.format("Configuration with name '%s' not found.", name)); }
@Override protected UnknownDomainObjectException createNotFoundException(String name) { return new UnknownTaskException(String.format("Task with name '%s' not found in %s.", name, project)); }
public T getByName(String name, Closure configureClosure) throws UnknownDomainObjectException { T t = getByName(name); ConfigureUtil.configure(configureClosure, t); return t; }
@Override public T getByName(String name, Action<? super T> configureAction) throws UnknownDomainObjectException { T t = getByName(name); configureAction.execute(t); return t; }
public T getAt(String name) throws UnknownDomainObjectException { return getByName(name); }
protected UnknownDomainObjectException createNotFoundException(String name) { return new UnknownDomainObjectException(String.format("%s with name '%s' not found.", getTypeDisplayName(), name)); }
@Override protected UnknownDomainObjectException createNotFoundException(String name) { return new UnknownRepositoryException(String.format("Repository with name '%s' not found.", name)); }
public U getAt(String name) throws UnknownDomainObjectException { return delegate.getAt(name); }
public U getByName(String name) throws UnknownDomainObjectException { return delegate.getByName(name); }
public U getByName(String name, Closure configureClosure) throws UnknownDomainObjectException { return delegate.getByName(name, configureClosure); }
@Override public U getByName(String name, Action<? super U> configureAction) throws UnknownDomainObjectException { return delegate.getByName(name, configureAction); }
public Object getByName(String name) { if (!hasExtension(name)) { throw new UnknownDomainObjectException("Extension with name '" + name + "' does not exist. Currently registered extension names: " + extensions.keySet()); } return findByName(name); }
/** * Looks for the extension of a given type (useful to avoid casting). If none found it will throw an exception. * * @param type extension type * @return extension, never null * @throws UnknownDomainObjectException When the given extension is not found. */ <T> T getByType(Class<T> type) throws UnknownDomainObjectException;
/** * Looks for the extension of a given name. If none found it will throw an exception. * * @param name extension name * @return extension, never null * @throws UnknownDomainObjectException When the given extension is not found. */ Object getByName(String name) throws UnknownDomainObjectException;