Search in sources :

Example 6 with RepositoryMapping

use of gen.core.project.RepositoryMapping in project omegat by omegat-org.

the class ConvertProject26to37team method convert.

private static void convert(File projectRootFolder) throws Exception {
    ProjectProperties props = ProjectFileStorage.loadProjectProperties(projectRootFolder);
    String version;
    String url;
    RepositoryDefinition def = new RepositoryDefinition();
    if (isSVNDirectory(projectRootFolder)) {
        url = getSVNUrl(projectRootFolder);
        def.setType("svn");
        version = getSVNTmxVersion(projectRootFolder);
    } else {
        url = getGITUrl(projectRootFolder);
        def.setType("git");
        version = getGITTmxVersion(projectRootFolder);
    }
    if (url == null) {
        throw new Exception("Repository URL not defined");
    }
    def.setUrl(url);
    saveVersion(projectRootFolder, "omegat/project_save.tmx", version);
    // map full project
    RepositoryMapping map = new RepositoryMapping();
    map.setLocal("");
    map.setRepository("");
    def.getMapping().add(map);
    props.setRepositories(new ArrayList<RepositoryDefinition>());
    props.getRepositories().add(def);
    ProjectFileStorage.writeProjectFile(props);
    // all data saved - remove old repository
    FileUtils.deleteDirectory(new File(projectRootFolder, ".svn"));
    FileUtils.deleteDirectory(new File(projectRootFolder, ".git"));
}
Also used : RepositoryDefinition(gen.core.project.RepositoryDefinition) RepositoryMapping(gen.core.project.RepositoryMapping) ProjectProperties(org.omegat.core.data.ProjectProperties) File(java.io.File) IOException(java.io.IOException)

Example 7 with RepositoryMapping

use of gen.core.project.RepositoryMapping in project omegat by omegat-org.

the class ProjectUICommands method projectTeamCreate.

public static void projectTeamCreate() {
    UIThreadsUtil.mustBeSwingThread();
    if (Core.getProject().isProjectLoaded()) {
        return;
    }
    new SwingWorker<Void, Void>() {

        File projectRoot;

        protected Void doInBackground() throws Exception {
            Core.getMainWindow().showStatusMessageRB(null);
            final NewTeamProject dialog = new NewTeamProject(Core.getMainWindow().getApplicationFrame());
            dialog.setVisible(true);
            if (!dialog.ok) {
                Core.getMainWindow().showStatusMessageRB("TEAM_CANCELLED");
                return null;
            }
            IMainWindow mainWindow = Core.getMainWindow();
            Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
            Cursor oldCursor = mainWindow.getCursor();
            mainWindow.setCursor(hourglassCursor);
            Core.getMainWindow().showStatusMessageRB("CT_DOWNLOADING_PROJECT");
            // retrieve omegat.project
            projectRoot = new File(dialog.getSaveLocation());
            List<RepositoryDefinition> repos = new ArrayList<RepositoryDefinition>();
            RepositoryDefinition repo = new RepositoryDefinition();
            repos.add(repo);
            repo.setType(dialog.getRepoType());
            repo.setUrl(dialog.getRepoUrl());
            RepositoryMapping mapping = new RepositoryMapping();
            mapping.setLocal("");
            mapping.setRepository("");
            repo.getMapping().add(mapping);
            RemoteRepositoryProvider remoteRepositoryProvider = new RemoteRepositoryProvider(projectRoot, repos);
            remoteRepositoryProvider.switchAllToLatest();
            for (String file : new String[] { OConsts.FILE_PROJECT, OConsts.DEFAULT_INTERNAL + '/' + FilterMaster.FILE_FILTERS, OConsts.DEFAULT_INTERNAL + '/' + SRX.CONF_SENTSEG }) {
                remoteRepositoryProvider.copyFilesFromRepoToProject(file);
            }
            ProjectProperties props = ProjectFileStorage.loadProjectProperties(projectRoot);
            if (props.getRepositories() == null) {
                // We assume it's a 3.6 style project with no repository mapping,
                // so we add root repository mapping
                props.setRepositories(repos);
            }
            // We write in all cases, because we might have added default excludes, for instance
            ProjectFileStorage.writeProjectFile(props);
            // String projectFileURL = dialog.txtRepositoryOrProjectFileURL.getText();
            // File localDirectory = new File(dialog.txtDirectory.getText());
            // try {
            // localDirectory.mkdirs();
            // byte[] projectFile = WikiGet.getURLasByteArray(projectFileURL);
            // FileUtils.writeByteArrayToFile(new File(localDirectory, OConsts.FILE_PROJECT), projectFile);
            // } catch (Exception ex) {
            // ex.printStackTrace();
            // Core.getMainWindow().displayErrorRB(ex, "TEAM_CHECKOUT_ERROR");
            // mainWindow.setCursor(oldCursor);
            // return null;
            // }
            // projectOpen(localDirectory);
            mainWindow.setCursor(oldCursor);
            return null;
        }

        @Override
        protected void done() {
            Core.getMainWindow().showProgressMessage(" ");
            try {
                get();
                if (projectRoot != null) {
                    // don't ask open if user cancelled previous dialog
                    SwingUtilities.invokeLater(() -> {
                        Core.getEditor().requestFocus();
                        projectOpen(projectRoot);
                    });
                }
            } catch (Exception ex) {
                Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_DOWNLOAD_TEAM_PROJECT");
                Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_DOWNLOAD_TEAM_PROJECT");
            }
        }
    }.execute();
}
Also used : RemoteRepositoryProvider(org.omegat.core.team2.RemoteRepositoryProvider) NewTeamProject(org.omegat.gui.dialogs.NewTeamProject) ProjectProperties(org.omegat.core.data.ProjectProperties) Cursor(java.awt.Cursor) KnownException(org.omegat.core.KnownException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RepositoryDefinition(gen.core.project.RepositoryDefinition) RepositoryMapping(gen.core.project.RepositoryMapping) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Aggregations

RepositoryMapping (gen.core.project.RepositoryMapping)7 RepositoryDefinition (gen.core.project.RepositoryDefinition)6 File (java.io.File)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ProjectProperties (org.omegat.core.data.ProjectProperties)2 Cursor (java.awt.Cursor)1 List (java.util.List)1 Properties (java.util.Properties)1 ExecutionException (java.util.concurrent.ExecutionException)1 KnownException (org.omegat.core.KnownException)1 RemoteRepositoryProvider (org.omegat.core.team2.RemoteRepositoryProvider)1 NewTeamProject (org.omegat.gui.dialogs.NewTeamProject)1