public static String toClasspath(URL cp) { try { String loc = cp.toURI().toString().replace("file:", ""); int ind = loc.indexOf("jar!"); if (ind == -1) { return loc; } return loc.substring(0, ind+3); } catch (Exception e) { throw X_Debug.rethrow(e); } } public static String[] toStrings(URL ... cp) {
@Override public Object convert(Object from) { Object parent = converter.convert(from); try { return rootMethod.invoke(parent); } catch (Exception e) { throw X_Debug.rethrow(e); } } };
@Override public Object convert(final Object from) { final Object parent = converter.convert(from); try { return rootMethod.invoke(parent); } catch (final Exception e) { throw X_Debug.rethrow(e); } } };
public String readAll() { StringBuilder b = new StringBuilder(); try { for (String line : readLines()) b.append(line).append('\n'); return b.toString(); } catch (IOException e) { throw X_Debug.rethrow(e); } }
public DigesterJre() { try { digest = MessageDigest.getInstance(getAlgorithm()); } catch (final NoSuchAlgorithmException e) { throw X_Debug.rethrow(e); } }
return Class.forName(cls); } catch (final ClassNotFoundException e) { throw X_Debug.rethrow(e);
@SuppressWarnings("unchecked") protected <T, U extends UserInterface<T>> U newUi(Class<? extends T> type, Class<? super U> uiType) { if (uiType == null) { throw new NullPointerException("Must specify UI type for "+type); } try { return (U) uiType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { X_Log.error(getClass(), "Unable to instantiate",uiType, e); throw X_Debug.rethrow(e); } }
public static Model loadPom(String fileLocation) { try { return service.loadPomFile(fileLocation); } catch (Exception e) { throw X_Debug.rethrow(e); } }
public static Model loadPomString(String pomString) { try { return service.loadPomString(pomString); } catch (Exception e) { throw X_Debug.rethrow(e); } }
@Override public UiRenderer renderInto(UserInterface ui, UiRenderingContext ctx, String path, Object value) { if (ui instanceof Appendable) { try { Appendable out = (Appendable)ui; if (ctx.isTemplateSet()) { String toString = ctx.applyTemplate(path, value); out.append(toString); } else { out.append(String.valueOf(value)); } } catch (IOException e) { throw X_Debug.rethrow(e); } } return this; }
/** * @param propertyType * @param src * @param primitives * @param ctx * @return */ @SuppressWarnings("unchecked") protected Object readEnum(final Class propertyType, final CharIterator src, final PrimitiveSerializer primitives, final ModelDeserializationContext ctx) { try { final int ordinal = primitives.deserializeInt(src); if (ordinal == -1) { return null; } final Method method = propertyType.getMethod("values"); final Object values = method.invoke(null); return Array.get(values, ordinal); } catch (final Throwable e) { X_Log.error(getClass(), "Error reading enum "+propertyType+" from "+src); throw X_Debug.rethrow(e); } }
protected <X> X create(Class<? extends X> renderer) { try { return renderer.newInstance(); } catch (InstantiationException e) { throw X_Debug.rethrow(e.getCause() == null ? e : e.getCause()); } catch (IllegalAccessException e) { throw X_Util.rethrow(e); } }
protected String computeUuid(final PrimitiveSerializer primitives) { // Compute the checksum of the policy itself. That checksum will become our UUID, // which will then be appended before the policy itself. final String result = calculateSerialization(primitives); final Digester digest = X_Inject.instance(Digester.class); byte[] asBytes; try { asBytes = result.getBytes("UTF-8"); } catch (final UnsupportedEncodingException e) { throw X_Debug.rethrow(e); } final byte[] uuid = digest.digest(asBytes); return digest.toString(uuid); }
public static URL[] compileScopeUrls(MavenProject project, MavenSession session) { try { List<String> compile = project.getCompileClasspathElements(); X_Log.info(X_Maven.class,"Compile classpath",compile); X_Log.info(X_Maven.class,"Runtime classpath",project.getRuntimeClasspathElements()); if (project.hasLifecyclePhase("test-classes")) { List<String> testElements = project.getTestClasspathElements(); testElements.addAll(compile); compile = testElements; } URL[] urls = new URL[compile.size()]; for (int i = compile.size(); i-- > 0;) { urls[i] = X_Dev.toUrl(compile.get(i)); } return urls; } catch (DependencyResolutionRequiredException e) { throw X_Debug.rethrow(e); } }
@Override public ArtifactResult loadArtifact(String groupId, String artifactId, String classifier, String extension, String version) { Moment before = X_Time.now(); RepositorySystem repoSystem = this.repoSystem.get(); RepositorySystemSession session = this.session.get(); DefaultArtifact artifact = new DefaultArtifact( groupId,artifactId,classifier, X_String.isEmpty(extension) ? "jar" : extension, version); try { ArtifactRequest request = new ArtifactRequest(artifact, remoteRepos(), null); return repoSystem.resolveArtifact(session, request); } catch (ArtifactResolutionException e) { X_Log.log(getClass(), getLogLevel(), "Resolved? ", e.getResult().isResolved(), e.getResult().getExceptions()); X_Log.log(getClass(), getLogLevel(), "Could not download " + artifact, e); throw X_Debug.rethrow(e); } finally { if (X_Log.loggable(LogLevel.DEBUG)) { X_Log.debug("Resolved: " + artifact.toString() + " in " + X_Time.difference(before)); } } }
@SuppressWarnings({"rawtypes", "unchecked"}) protected void recursiveRender(UiRenderingContext ctx, UiRenderer renderer, T model){ UiRendererSelector selector = ctx.getSelector(); if (ctx.isWrapper()) { for (String key : ctx.getBeanValueProvider().getChildKeys()) { try { if (selector.useRenderer(this, renderer, key, model)) { renderer.renderInto(this, ctx, key, model); } } catch(ClassCastException e) { e.printStackTrace(); } catch(Throwable e) { throw X_Debug.rethrow(e); } } } else { if (selector.useRenderer(this, renderer, ctx.getName(), model)) { renderer.renderInto(this, ctx, ctx.getName(), model); } } }