use of com.twinsoft.convertigo.engine.enums.ArchiveExportOption in project convertigo by convertigo.
the class CarUtils method makeArchive.
public static File makeArchive(File file, Project project, Set<ArchiveExportOption> archiveExportOptions) throws EngineException {
Set<File> undeployedFiles = getUndeployedFiles(project.getName());
String projectName = project.getName();
String dirPath = project.getDirPath();
File projectDir = new File(dirPath);
File skipTestCase = null;
try {
if (!archiveExportOptions.contains(ArchiveExportOption.includeTestCase)) {
skipTestCase = new File(projectDir, "_private/noTestCase/c8oProject.yaml");
CarUtils.exportProject(project, skipTestCase.getAbsolutePath(), false);
}
for (ArchiveExportOption opt : ArchiveExportOption.values()) {
if (!archiveExportOptions.contains(opt)) {
for (File dir : opt.dirs(projectDir)) {
undeployedFiles.add(dir);
}
}
}
FileUtils.deleteQuietly(file);
File f = ZipUtils.makeZip(file.getAbsolutePath(), dirPath, projectName, undeployedFiles);
if (skipTestCase != null) {
Map<String, String> zip_properties = new HashMap<>();
zip_properties.put("create", "false");
zip_properties.put("encoding", "UTF-8");
URI zip_disk = URI.create("jar:" + f.toURI());
try (FileSystem zipfs = FileSystems.newFileSystem(zip_disk, zip_properties)) {
Path addNewFile = skipTestCase.getParentFile().toPath();
Files.walk(addNewFile).forEach(p -> {
try {
String relat = addNewFile.relativize(p).toString();
if (!relat.isEmpty()) {
Files.copy(p, zipfs.getPath(projectName, relat));
}
} catch (IOException e) {
Engine.logEngine.debug("(CarUtils) failed to copy project without TestCase: " + e);
}
});
}
}
return f;
} catch (Exception e) {
throw new EngineException("Unable to make the archive file for the project \"" + projectName + "\".", e);
} finally {
if (skipTestCase != null) {
FileUtils.deleteQuietly(skipTestCase.getParentFile());
}
}
}
use of com.twinsoft.convertigo.engine.enums.ArchiveExportOption in project convertigo by convertigo.
the class Export method writeResponseResult.
@Override
protected void writeResponseResult(HttpServletRequest request, HttpServletResponse response) throws IOException, EngineException {
String projectName = request.getParameter("projectName");
String exportOptionsTxt = request.getParameter("exportOptions");
HeaderName.ContentDisposition.setHeader(response, "attachment; filename=\"" + projectName + ".car\"");
response.setContentType(MimeType.Zip.value());
// if any, backup existing CAR file
File f = new File(Engine.projectDir(projectName) + ".car");
long lastDate = -1;
if (f.exists()) {
lastDate = f.lastModified();
File oldFile = new File(Engine.projectDir(projectName) + ".car.old");
FileUtils.deleteQuietly(oldFile);
f.renameTo(oldFile);
}
if (!Engine.theApp.databaseObjectsManager.existsProject(projectName)) {
throw new IllegalArgumentException("The project '" + projectName + "' does not exist!");
}
Set<ArchiveExportOption> exportOptions = ArchiveExportOption.all;
if (exportOptionsTxt != null) {
try {
JSONObject exportOptionsJson = new JSONObject(exportOptionsTxt);
exportOptions = new HashSet<ArchiveExportOption>(exportOptions);
for (Iterator<?> i = exportOptionsJson.keys(); i.hasNext(); ) {
String key = (String) i.next();
try {
ArchiveExportOption opt = ArchiveExportOption.valueOf(key);
if (!exportOptionsJson.getBoolean(key)) {
exportOptions.remove(opt);
}
} catch (Exception e) {
Engine.logAdmin.warn("Export cannot find ArchiveExportOption:" + key);
}
}
} catch (JSONException e) {
throw new EngineException("Export unable to parse JSON exportOptions: " + exportOptionsTxt);
}
}
// build a new CAR file from project directory
f = CarUtils.makeArchive(projectName, exportOptions);
// upload CAR file to admin
HeaderName.ContentLength.setHeader(response, "" + f.length());
if (f.exists()) {
if (lastDate > 0) {
f.setLastModified(lastDate);
}
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
OutputStream outStream = response.getOutputStream();
byte[] buffer = new byte[1024];
int nbReadBytes;
while ((nbReadBytes = bis.read(buffer, 0, 1024)) > 0) {
outStream.write(buffer, 0, nbReadBytes);
}
bis.close();
}
Engine.logAdmin.info("The project '" + projectName + "' has been exported");
}
use of com.twinsoft.convertigo.engine.enums.ArchiveExportOption in project convertigo by convertigo.
the class ArchiveExportOptionDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout gl = new GridLayout(1, false);
gl.verticalSpacing = 10;
composite.setLayout(gl);
Label label = new Label(composite, SWT.NONE);
label.setText("You can update the version of your project before export or deployment.");
Group group = new Group(composite, SWT.NONE);
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
group.setText("If you wish to, please change the value below: ");
group.setLayout(new FillLayout(SWT.VERTICAL));
versionSWT = new Text(group, SWT.NONE);
versionSWT.setText(version);
group = new Group(composite, SWT.NONE);
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
group.setText("Check to include: ");
group.setLayout(new FillLayout(SWT.VERTICAL));
archiveExportOptionsSWT = new Button[ArchiveExportOption.values().length];
int i = 0;
File projectDir = project.getDirFile();
for (ArchiveExportOption option : ArchiveExportOption.values()) {
long size = option.size(projectDir);
if (size > 0) {
Button check = new Button(group, SWT.CHECK);
check.setData(option);
if (option == ArchiveExportOption.includeTestCase) {
check.setText(option.display());
} else {
check.setText(option.display() + " [" + FileUtils.byteCountToDisplaySize(size) + "]");
}
check.setSelection(archiveExportOptions.contains(option));
archiveExportOptionsSWT[i++] = check;
} else {
archiveExportOptionsSWT[i++] = null;
}
}
IApplicationComponent app = project.getMobileApplication() != null ? project.getMobileApplication().getApplicationComponent() : null;
String msg = app != null ? app.getUnbuiltMessage() : null;
if (msg != null) {
label = new Label(composite, SWT.NONE);
label.setText(msg + "\nOnce the build finished, you can " + (bDeploy ? "deploy" : "export") + " again.");
SwtUtils.applyStyle(label, "{ color: red }");
}
composite.pack(true);
return composite;
}
use of com.twinsoft.convertigo.engine.enums.ArchiveExportOption in project convertigo by convertigo.
the class ExportOptions method getServiceResult.
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
String projectName = request.getParameter("projectName");
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
File projectDir = project.getDirFile();
Element root = document.getDocumentElement();
Element options = document.createElement("options");
for (ArchiveExportOption o : ArchiveExportOption.values()) {
long size = o.size(projectDir);
if (size > 0) {
Element e = document.createElement("option");
e.setAttribute("name", o.name());
if (o == ArchiveExportOption.includeTestCase) {
e.setAttribute("display", o.display());
} else {
e.setAttribute("display", o.display() + " [" + FileUtils.byteCountToDisplaySize(size) + "]");
}
options.appendChild(e);
}
}
;
root.appendChild(options);
}
Aggregations