External system: import timestamps added to external project info for the obtained project structure (DataNode<ProjectData>).

These timestamps can also be used to determine failed import:  lastImportTimestamp > lastSuccessfulImportTimestamp
This commit is contained in:
Vladislav.Soroka
2014-09-22 19:23:18 +04:00
parent 66c70dc335
commit 73dc172b53
5 changed files with 181 additions and 12 deletions
@@ -0,0 +1,39 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.externalSystem.model;
import com.intellij.openapi.externalSystem.model.project.ProjectData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author Vladislav.Soroka
* @since 9/22/2014
*/
public interface ExternalProjectInfo {
@NotNull
ProjectSystemId getProjectSystemId();
@NotNull
String getExternalProjectPath();
@Nullable
DataNode<ProjectData> getExternalProjectStructure();
long getLastSuccessfulImportTimestamp();
long getLastImportTimestamp();
}
@@ -0,0 +1,91 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.externalSystem.model.internal;
import com.intellij.openapi.externalSystem.model.DataNode;
import com.intellij.openapi.externalSystem.model.ExternalProjectInfo;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.model.project.ProjectData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.Serializable;
/**
* @author Vladislav.Soroka
* @since 9/22/2014
*/
public class InternalExternalProjectInfo implements ExternalProjectInfo, Serializable {
private static final long serialVersionUID = 1L;
@NotNull
private final ProjectSystemId myProjectSystemId;
@NotNull
private final String myExternalProjectPath;
@Nullable
private DataNode<ProjectData> myExternalProjectStructure;
private long lastSuccessfulImportTimestamp = -1;
private long lastImportTimestamp = -1;
public InternalExternalProjectInfo(@NotNull ProjectSystemId projectSystemId,
@NotNull String externalProjectPath,
@Nullable DataNode<ProjectData> externalProjectStructure) {
myProjectSystemId = projectSystemId;
myExternalProjectPath = externalProjectPath;
myExternalProjectStructure = externalProjectStructure;
}
@Override
@NotNull
public ProjectSystemId getProjectSystemId() {
return myProjectSystemId;
}
@Override
@NotNull
public String getExternalProjectPath() {
return myExternalProjectPath;
}
@Override
@Nullable
public DataNode<ProjectData> getExternalProjectStructure() {
return myExternalProjectStructure;
}
@Override
public long getLastSuccessfulImportTimestamp() {
return lastSuccessfulImportTimestamp;
}
@Override
public long getLastImportTimestamp() {
return lastImportTimestamp;
}
public void setExternalProjectStructure(@Nullable DataNode<ProjectData> externalProjectStructure) {
myExternalProjectStructure = externalProjectStructure;
}
public void setLastSuccessfulImportTimestamp(long lastSuccessfulImportTimestamp) {
this.lastSuccessfulImportTimestamp = lastSuccessfulImportTimestamp;
}
public void setLastImportTimestamp(long lastImportTimestamp) {
this.lastImportTimestamp = lastImportTimestamp;
}
}
@@ -2,9 +2,11 @@ package com.intellij.openapi.externalSystem.service.internal;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.externalSystem.model.DataNode;
import com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.model.project.ProjectData;
import com.intellij.openapi.externalSystem.model.settings.ExternalSystemExecutionSettings;
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskState;
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType;
import com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager;
import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager;
@@ -51,7 +53,6 @@ public class ExternalSystemResolveProjectTask extends AbstractExternalSystemTask
if (project == null) {
return;
}
ProjectDataManager.getInstance().updateExternalProjectData(ideProject, project);
myExternalProject.set(project);
}
@@ -73,4 +74,17 @@ public class ExternalSystemResolveProjectTask extends AbstractExternalSystemTask
protected String wrapProgressText(@NotNull String text) {
return ExternalSystemBundle.message("progress.update.text", getExternalSystemId().getReadableName(), text);
}
@Override
protected void setState(@NotNull ExternalSystemTaskState state) {
super.setState(state);
if (state.isStopped()) {
InternalExternalProjectInfo projectInfo =
new InternalExternalProjectInfo(getExternalSystemId(), getExternalProjectPath(), getExternalProject());
final long currentTimeMillis = System.currentTimeMillis();
projectInfo.setLastImportTimestamp(currentTimeMillis);
projectInfo.setLastSuccessfulImportTimestamp(state == ExternalSystemTaskState.FAILED ? -1 : currentTimeMillis);
ProjectDataManager.getInstance().updateExternalProjectData(getIdeProject(), projectInfo);
}
}
}
@@ -19,7 +19,9 @@ import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.SettingsSavingComponent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.externalSystem.model.DataNode;
import com.intellij.openapi.externalSystem.model.ExternalProjectInfo;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo;
import com.intellij.openapi.externalSystem.model.project.ProjectData;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
@@ -39,8 +41,8 @@ public class ExternalProjectsDataStorage implements SettingsSavingComponent {
@NotNull
private final Project myProject;
@NotNull
private final Map<Pair<ProjectSystemId, String>, DataNode<ProjectData>> myExternalRootProjects =
new ConcurrentHashMap<Pair<ProjectSystemId, String>, DataNode<ProjectData>>();
private final Map<Pair<ProjectSystemId, String>, InternalExternalProjectInfo> myExternalRootProjects =
new ConcurrentHashMap<Pair<ProjectSystemId, String>, InternalExternalProjectInfo>();
public static ExternalProjectsDataStorage getInstance(@NotNull Project project) {
return ServiceManager.getService(project, ExternalProjectsDataStorage.class);
@@ -59,14 +61,37 @@ public class ExternalProjectsDataStorage implements SettingsSavingComponent {
// TODO [Vlad] save data if changed
}
void add(@NotNull DataNode<ProjectData> projectDataNode) {
final String projectPath = projectDataNode.getData().getLinkedExternalProjectPath();
final ProjectSystemId projectSystemId = projectDataNode.getData().getOwner();
myExternalRootProjects.put(Pair.create(projectSystemId, projectPath), projectDataNode);
void add(@NotNull ExternalProjectInfo externalProjectInfo) {
final ProjectSystemId projectSystemId = externalProjectInfo.getProjectSystemId();
final String projectPath = externalProjectInfo.getExternalProjectPath();
DataNode<ProjectData> externalProjectStructure = externalProjectInfo.getExternalProjectStructure();
long lastSuccessfulImportTimestamp = externalProjectInfo.getLastSuccessfulImportTimestamp();
long lastImportTimestamp = externalProjectInfo.getLastImportTimestamp();
final Pair<ProjectSystemId, String> key = Pair.create(projectSystemId, projectPath);
final InternalExternalProjectInfo old = myExternalRootProjects.get(key);
if (old != null) {
lastImportTimestamp = externalProjectInfo.getLastImportTimestamp();
if (lastSuccessfulImportTimestamp == -1) {
lastSuccessfulImportTimestamp = old.getLastSuccessfulImportTimestamp();
}
if (externalProjectInfo.getExternalProjectStructure() == null) {
externalProjectStructure = old.getExternalProjectStructure();
}
}
InternalExternalProjectInfo merged = new InternalExternalProjectInfo(
projectSystemId,
projectPath,
externalProjectStructure
);
merged.setLastImportTimestamp(lastImportTimestamp);
merged.setLastSuccessfulImportTimestamp(lastSuccessfulImportTimestamp);
myExternalRootProjects.put(key, merged);
}
@Nullable
DataNode<ProjectData> get(@NotNull ProjectSystemId projectSystemId, @NotNull String externalProjectPath) {
ExternalProjectInfo get(@NotNull ProjectSystemId projectSystemId, @NotNull String externalProjectPath) {
return myExternalRootProjects.get(Pair.create(projectSystemId, externalProjectPath));
}
}
@@ -18,9 +18,9 @@ package com.intellij.openapi.externalSystem.service.project.manage;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.externalSystem.model.DataNode;
import com.intellij.openapi.externalSystem.model.ExternalProjectInfo;
import com.intellij.openapi.externalSystem.model.Key;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.model.project.ProjectData;
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NotNullLazyValue;
@@ -147,12 +147,12 @@ public class ProjectDataManager {
}
}
public void updateExternalProjectData(@NotNull Project project, @NotNull DataNode<ProjectData> projectDataNode) {
ExternalProjectsDataStorage.getInstance(project).add(projectDataNode);
public void updateExternalProjectData(@NotNull Project project, @NotNull ExternalProjectInfo externalProjectInfo) {
ExternalProjectsDataStorage.getInstance(project).add(externalProjectInfo);
}
@Nullable
public DataNode<ProjectData> getExternalProjectData(@NotNull Project project, @NotNull ProjectSystemId projectSystemId, @NotNull String externalProjectPath) {
public ExternalProjectInfo getExternalProjectData(@NotNull Project project, @NotNull ProjectSystemId projectSystemId, @NotNull String externalProjectPath) {
return ExternalProjectsDataStorage.getInstance(project).get(projectSystemId, externalProjectPath);
}
}