Import and use protobufs outside of lib directory - dart - flutter

I am trying to build a web application with with Flutter for the frontend, go for the backend and gRPC as the communication protocol. In an effort to avoid using identical protobufs in 2 different directories, I refactored the protobufs and compiled them into a third directory outside of the client and server folders (all within the same repo). Now I'm having trouble accessing the compiled dart protobufs from the client code. Here is my folder structure:
.
|-- client/
|-- pubspec.yaml
|-- protos/
|-- dart_protos/
|-- .dart_tool/
|-- .packages
|-- cards.pb.dart
|-- cards.pbenum.dart
|-- cards.pbjson.dart
|-- cards.pbserver.dart
|-- pubspec.lock
|-- pubscpec.yaml
|-- go_protos/
|-- cards.proto
|-- server/
Here is how I am defining my dependencies in my client/pubspec.yaml
dependencies:
flutter:
sdk: flutter
recase: ^4.0.0
search_choices: ^2.0.7
tcb_protos:
path: ../protos/dart_protos
My protos/dart_protos/pubspec.yaml:
name: tcb_protos
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
protobuf: ^1.1.4
protoc_plugin: ^19.3.1
And how I am importing the protobuf:
import 'package:tcb_protos/cards.pb.dart';
So I am running into a couple of issues:
I am getting Target of URI hasn't been generated: 'package:tcb_protos/cards.pb.dart'. on the import
I am unable to use the protobuf based on the import, and VSCode's intellisense isn't working on the package (which I am assuming is because either the package definition or import is wrong)
How can I use the protobuf in my Flutter widgets?

You need to have the proto .pb.dart files inside a lib/ folder.
I made a small example here: https://github.com/sigurdm/shared_proto_example
If you want to have protos in different packages that reference each other, that is currently not supported: https://github.com/google/protobuf.dart/issues/295

Related

Timed out while searching for 'workspaceContains' VSCODE

Extensions sometime not activated, in Log (Extension Hosts) appear this message
[2022-01-07 08:25:00.723] [exthost] [info] Not activating extension 'apollographql.vscode-apollo': Timed out while searching for 'workspaceContains' pattern **/apollo.config.[jt]s,**/apollo.config.cjs
and its happen with some extensions too. I checked config file is already in correct folder
What's I Tried so Far
Reload Window
Reinstall Extensions
Install Another Version (Ext)
Completely delete Ext files in %USERPROFILE%\.vscode\extensions
Activation Events apollographql.vscode-apollo
workspaceContains:**/apollo.config.[jt]s
workspaceContains:**/apollo.config.cjs
Workspace Tree
|-- Workspace
|-- Some Project
|-- Vue Project
|-- apollo.config.js
|-- Some Project
Reply in comment, if you need spesific settings.
Thanks in Advance.

SBT Assembly remove classes from another JAR

This is the package structure of my repo:
src
|-- main
|-- scala
|-- me.sparker0i.spark
|-- runner
|-- Runner.scala
|-- utils
|-- Constants.scala
|-- DatabaseUtils.scala
|-- service
|-- Service.scala
|-- Transform.scala [extends Service]
|-- Fetch.scala [extends Service]
|-- <32 more>
|-- Test.scala
I want to split this application into two such that one application remains the core, while the other uses the core jar as a libraryDependencies:
Core Repo structure:
src
|-- main
|-- scala
|-- me.sparker0i.spark
|-- runner
|-- Runner.scala
|-- utils
|-- Constants.scala
|-- DatabaseUtils.scala
|-- service
|-- Service.scala
|-- Test.scala
Independent Repo:
src
|-- main
|-- scala
|-- me.sparker0i.spark
|-- service
|-- Transform.scala [extends Service from Core Repo JAR]
|-- Fetch.scala [extends Service from Core Repo JAR]
|-- <32 more>
Now inside the Independent Repo, I've referenced the Core Repo JAR inside libraryDependencies. I need that Core JAR to run the test cases of the Independent Repo inside our Jenkins CICD, but not when I need to package the Independent Repo.
When I do sbt assembly, how do I ensure that I don't get the contents of the Core JAR inside the Independent JAR? The reason being I will be running the Main class inside the Core JAR, but will also be supplying the Independent JAR as a class path.
Is there some way the above requirement can be achieved using sbt?
You could declare the dependency with scope Provided. This is exactly meant for this use case, i.e. a dependency is provided somehow at runtime but not part of the package.
groupId % core % version % Provided

How do I re-root a eclipse project to a parent folder without break it?

I did a project with eclipse and I shared it on github. After much work, I realized that the whole project is in a folder called 'projectname'.
A graphic explains it better.
|-- README.md
`-- projectname
|-- model
|-- public
| |-- images
| |-- css
| `-- index.html
|-- package.json
`-- app.js
But I need it in the base directory.
|-- README.md
|-- model
|-- public
| |-- images
| |-- css
| `-- index.html
|-- package.json
`-- app.js
So how do I move these files without breaking the repository or break the eclipse project?
Delete the project from inside of Eclipse, making sure to NOT remove the underlying files, fix the git repository, and then re-import the project from the Git Repositories view into the workspace.

OSS Nexus: how to use REST API to retrieve last version as a text

I'd like to retrieve the latest version name (as text) to be able to rename the artificats retrieved from Nexus which have timestamps.
What I do is create an archive of several archives containing in-house jar projects, dependencies, related scripts, ... But if the packaged jars are snapshots, the archives end up with timestamps when downloaded. Those timestamps replace the X.X.X-SNAPSHOT extension of the archive and I cannot make any automated script to perform some tasks like extracting the archive, renaming the directory, make some symbolic links, ...
I did not find anything related to this in the rest api documentation. Is there a simple way to do this with the rest api or some kind of scripting?
Thanks.
Edit:
From the below answer I managed to retrieve the latest snapshot version using LATEST instead of the version name:
Then using a script I can retrieve the base version.
#!/bin/bash
VERSION=`curl --silent "http://redmine.saic.int:8081/nexus/service/local/artifact/maven/resolve?r=snapshots&g=com.g2mobility&a=G2-Modem-Mgr&v=LATEST&c=executable&e=tar.gz" | sed -n 's|<baseVersion>\(.*\)</baseVersion>|\1|p'`
VERSION=`echo "$VERSION" | tr -d ' '`
echo "Version is $VERSION"
Thanks!
Nexus has the following REST API for describing how Maven modules are resolved:
Artifact Maven Resolve
Example
To obtain the details about the following artifact:
<groupId>org.cometd.jetty</groupId>
<artifactId>cometd-jetty-client</artifactId>
<version>1.0-SNAPSHOT</version>
Use the following REST API:
https://oss.sonatype.org/service/local/artifact/maven/resolve?r=cometd-snapshots&g=org.cometd.jetty&a=cometd-jetty-client&v=1.0-SNAPSHOT&e=jar
Returns the following report:
<artifact-resolution>
<data>
<presentLocally>true</presentLocally>
<groupId>org.cometd.jetty</groupId>
<artifactId>cometd-jetty-client</artifactId>
<version>1.0-20090313.100344-2</version>
<baseVersion>1.0-SNAPSHOT</baseVersion>
<extension>jar</extension>
<snapshot>true</snapshot>
<snapshotBuildNumber>2</snapshotBuildNumber>
<snapshotTimeStamp>1236938624000</snapshotTimeStamp>
<sha1>0cbf7163f19bf4586e27632a1f742dd0c0e0036d</sha1>
<repositoryPath>/org/cometd/jetty/cometd-jetty-client/1.0-SNAPSHOT/cometd-jetty-client-1.0-20090313.100344-2.jar</repositoryPath>
</data>
</artifact-resolution>
This was an eariler deleted posting proposing an alternative way of assembling distributions from Maven repository content:
Ivy is an alternative dependency management client, which can be run from the command-line as follows:
java -jar ivy.jar -settings ivysettings.xml -dependency org.cometd.jetty cometd-jetty-client 1.0-SNAPSHOT -retrieve "distrib/[artifact]-[revision](-[classifier]).[ext]"
The retrieve option of the ivy command details how the downloaded files should be stored locally:
-- distrib
|-- cometd-api-1.0-SNAPSHOT.jar
|-- cometd-jetty-client-1.0-SNAPSHOT.jar
|-- cometd-jetty-client-1.0-SNAPSHOT-javadoc.jar
|-- cometd-jetty-client-1.0-SNAPSHOT-sources.jar
|-- cometd-jetty-server-1.0-SNAPSHOT.jar
|-- jetty-6.1.15.jar
|-- jetty-client-6.1.15.jar
|-- jetty-sslengine-6.1.15.jar
|-- jetty-util5-6.1.15.jar
|-- jetty-util-6.1.15.jar
`-- servlet-api-2.5-20081211.jar
The correct timestamped artifact is retrieved but the "SNAPSHOT" revision number is preserved, which is what I understand you're trying to do.
The ivysettings file details the repositories to be used when downloading artifacts:
<ivysettings>
<settings defaultResolver="repos"/>
<resolvers>
<chain name="repos">
<ibiblio name="central" m2compatible="true"/>
<ibiblio name="cometd-snapshot" root="https://oss.sonatype.org/content/repositories/cometd-snapshots/" m2compatible="true"/>
</chain>
</resolvers>
</ivysettings>
The documentation for the Maven Resolve Nexus REST API can be found here: https://maven.java.net/nexus-core-documentation-plugin/core/docs/rest.artifact.maven.resolve.html

my application stopped working with xulrunner 10.0.4

When I upgraded to centos 6 and xulrunner 10.0.4, my app stopped working. Xulrunner just hangs.
My directory structure:
.
|-- application.ini
|-- chrome
| |-- chrome.manifest
| `-- content
| |-- main.xul
| `-- main.xul.tpl.org
|-- defaults
| `-- preferences
| `-- prefs.js
According to example application from developer.mozilla.org, your application is missing the chrome.manifest as a sibling file of application.ini with the content:
manifest chrome/chrome.manifest
The funny thing is it works on xulrunner 12.0 but not on 10.0. Just add the file and your application should work.