/** * Constructs an ASTNodeArtifact from a FileArtifact. * * @param artifact file artifact */ public ASTNodeArtifact(final FileArtifact artifact) { assert (artifact != null); setRevision(artifact.getRevision()); ASTNode<?> astnode; if (artifact.isEmptyDummy()) { astnode = new ASTNode<>(); setEmptyDummy(true); } else { Program p = initProgram(); p.addSourceFile(artifact.getPath()); astnode = p; } this.astnode = astnode; renumber(1, this); }
public FileArtifact get(String id) throws ControllerException { if (id == null) { throw new ControllerException("Can not get artifact from null ID"); } File file = new File(getFolder(), id + ".zip"); if (!file.exists()) { throw new ControllerException("Can not find artifact from ID + " + id); } FileArtifact result = new FileArtifact(file); Properties props = new Properties(); File propFile = new File(getFolder(), id + ".properties"); if (propFile.exists() && !propFile.isDirectory()) { try { props.load(new FileInputStream(propFile)); result.setProperties(props); // TODO : Fill artifact } catch (IOException e) { LOG.debug("Can not load properties", e); } } return result; }
public String put(FileArtifact artifact) throws ControllerException { if (artifact == null || artifact.getFile() == null) { throw new ControllerException("Can not store a null artifact"); } String uuid = UUID.randomUUID().toString(); String finalName = uuid + ".zip"; File finalFile = new File(getFolder(), finalName); if (artifact.getFile() != null) { try { FileUtils.copyFile(artifact.getFile(), finalFile); } catch (IOException e) { throw new ControllerException(e); } } // TODO : Store information in a repository file Properties props = new Properties(); props.putAll(artifact.getProperties()); if (artifact.getUrl() != null) props.put("artifact.url", artifact.getUrl().toString()); if (artifact.getDate() != null) props.put("artifact.date", artifact.getDate().toString()); if (artifact.getType() != null) { props.put("artifact.type.name", artifact.getType().name); props.put("artifact.type.version", artifact.getType().version); } String propName = uuid + ".properties"; File propFile = new File(getFolder(), propName); try { props.store(new FileOutputStream(propFile), "Stored on " + new Date()); } catch (IOException e) { LOG.warn(e.getMessage()); } return uuid; }