Skip to content

Commit

Permalink
Merge pull request #3241 from Catrobat/hotfix-0.9.61
Browse files Browse the repository at this point in the history
Merge Hotfix 0.9.61 back into Master.
  • Loading branch information
wslany authored Jun 14, 2019
2 parents fb5428a + faacc9c commit ae027c2
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 15 deletions.
4 changes: 2 additions & 2 deletions catroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ android {
targetSdkVersion 26
applicationId appId
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
versionCode 61
versionCode 62
println "VersionCode is $versionCode"
versionName "0.9.60"
versionName "0.9.61"
println "VersionName is $versionName"
buildConfigField "String", "GIT_COMMIT_INFO", "\"${getGitCommitInfo()}\""
buildConfigField "String", "MAIN_URL_HTTPS", (project.hasProperty('useWebTest') ? '"https://web-test.catrob.at"' : '"https://share.catrob.at"')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2018 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* An additional term exception under section 7 of the GNU Affero
* General Public License, version 3, is available at
* http://developer.catrobat.org/license_additional_term
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.catrobat.catroid.test.io.asynctask;

import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.catrobat.catroid.common.DefaultProjectHandler;
import org.catrobat.catroid.content.Project;
import org.catrobat.catroid.io.asynctask.ProjectRenameTask;
import org.catrobat.catroid.test.utils.TestUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.File;
import java.io.IOException;

import static org.junit.Assert.assertEquals;

@RunWith(AndroidJUnit4.class)
public class ProjectRenameTaskTest {

private final String projectName = "testProject";
private final String renamedProjectName = "renamedTestProject";
private final String slashRenamedProject = "renamed/TestProject";
private final String slashEncodedRenamedProject = "renamed%2FTestProject";

private Project defaultProject;

@Before
public void setUp() throws IOException {
TestUtils.deleteProjects(projectName, renamedProjectName, slashEncodedRenamedProject);
defaultProject = DefaultProjectHandler.createAndSaveDefaultProject(projectName,
InstrumentationRegistry.getTargetContext());
}

@After
public void tearDown() throws IOException {
TestUtils.deleteProjects(projectName, renamedProjectName, slashEncodedRenamedProject);
}

@Test
public void projectRenameTaskTest() throws IOException {
File renamedDirectory = ProjectRenameTask.task(defaultProject.getDirectory(), renamedProjectName);
assertEquals(renamedProjectName, renamedDirectory.getName());
}

@Test
public void projectRenameSlashTaskTest() throws IOException {
File renamedDirectory = ProjectRenameTask.task(defaultProject.getDirectory(), slashRenamedProject);
assertEquals(slashEncodedRenamedProject, renamedDirectory.getName());
}

@Test
public void projectDirectoryRenameTest() throws IOException {
File expectedDirectory = new File(defaultProject.getDirectory().getParent(), renamedProjectName);
File renamedDirectory = ProjectRenameTask.task(defaultProject.getDirectory(), renamedProjectName);
assertEquals(expectedDirectory, renamedDirectory);
}

@Test
public void projectDirectoryRenameSlashTest() throws IOException {

File expectedDirectory = new File(defaultProject.getDirectory().getParent(), slashEncodedRenamedProject);
File renamedDirectory = ProjectRenameTask.task(defaultProject.getDirectory(), slashRenamedProject);
assertEquals(expectedDirectory, renamedDirectory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,26 @@ public ProjectRenameTask setListener(ProjectRenameListener listener) {
return this;
}

public static boolean task(File projectDir, String dstName) {
public static File task(File projectDir, String dstName) throws IOException {
File dstDir = new File(projectDir.getParent(), FileMetaDataExtractor.encodeSpecialCharsForFileSystem(dstName));

try {
return projectDir.renameTo(dstDir)
&& XstreamSerializer.renameProject(new File(dstDir, CODE_XML_FILE_NAME), dstName);
} catch (IOException e) {
Log.e(TAG, "Cannot rename project directory " + projectDir.getAbsolutePath() + " to " + dstName, e);
return false;
if (projectDir.renameTo(dstDir)
&& XstreamSerializer.renameProject(new File(dstDir, CODE_XML_FILE_NAME), dstName)) {
return dstDir;
} else {
throw new IOException("Cannot rename project directory " + projectDir.getAbsolutePath() + " to " + dstName);
}
}

@Override
protected Boolean doInBackground(Void... voids) {
return task(projectDir, dstName);
try {
task(projectDir, dstName);
return true;
} catch (IOException e) {
Log.e(TAG, "Creating renamed directory failed!", e);
return false;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.catrobat.catroid.web.ServerCalls;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -258,11 +259,13 @@ private void showProgressDialogAndUploadProject() {
String description = descriptionInputLayout.getEditText().getText().toString().trim();

if (!project.getName().equals(name)) {
ProjectRenameTask
.task(project.getDirectory(), name);
ProjectLoadTask
.task(project.getDirectory(), this);
project = ProjectManager.getInstance().getCurrentProject();
try {
File renamedDirectory = ProjectRenameTask.task(project.getDirectory(), name);
ProjectLoadTask.task(renamedDirectory, this);
project = ProjectManager.getInstance().getCurrentProject();
} catch (IOException e) {
Log.e(TAG, "Creating renamed directory failed!", e);
}
}

project.setDescription(description);
Expand Down

0 comments on commit ae027c2

Please sign in to comment.