/** * Constructor * * @throws IOException */ public JustAnotherPackageManager(Reporter reporter, Platform platform, File homeDir, File binDir) throws IOException { this.platform = platform; this.reporter = reporter; this.homeDir = homeDir; if (!homeDir.exists() && !homeDir.mkdirs()) throw new IllegalArgumentException("Could not create directory " + homeDir); repoDir = IO.getFile(homeDir, "repo"); if (!repoDir.exists() && !repoDir.mkdirs()) throw new IllegalArgumentException("Could not create directory " + repoDir); commandDir = new File(homeDir, COMMANDS); serviceDir = new File(homeDir, SERVICE); commandDir.mkdir(); serviceDir.mkdir(); service = new File(repoDir, SERVICE_JAR_FILE); if (!service.isFile()) init(); this.binDir = binDir; if (!binDir.exists() && !binDir.mkdirs()) throw new IllegalArgumentException("Could not create bin directory " + binDir); }
/** * @param data * @param target * @throws Exception * @throws IOException */ public String createService(ServiceData data) throws Exception, IOException { File sdir = new File(serviceDir, data.name); if (!sdir.exists() && !sdir.mkdirs()) { throw new IOException("Could not create directory " + data.sdir); } data.sdir = sdir.getAbsolutePath(); File lock = new File(data.sdir, LOCK); data.lock = lock.getAbsolutePath(); if (data.work == null) data.work = new File(data.sdir, "work").getAbsolutePath(); if (data.user == null) data.user = platform.user(); if (data.user == null) data.user = "******"; new File(data.work).mkdir(); if (data.log == null) data.log = new File(data.sdir, "log").getAbsolutePath(); // TODO // if (Data.validate(data) != null) // return "Invalid service data: " + Data.validate(data); if (service == null) throw new RuntimeException( "Missing biz.aQute.jpm.service in repo, should have been installed by init, try reiniting"); data.serviceLib = service.getAbsolutePath(); platform.chown(data.user, true, new File(data.sdir)); String s = platform.createService(data, null, false); if (s == null) storeData(new File(data.sdir, "data"), data); return s; }